Skip to content

Commit

Permalink
Add MustMarshal
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg committed Oct 4, 2023
1 parent d8927ad commit c0a49cb
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions jsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,13 @@ func UnmarshalFrom(r io.Reader, v any) error {
return nil
}

// MustMarshal an object to JSON, and panics if any error occurs.
func MustMarshal(obj any) []byte {
b, err := json.Marshal(obj)
if err != nil {
panic(err)
}
return b
}

var errMore = errors.New("body must contain only one JSON entity")

0 comments on commit c0a49cb

Please sign in to comment.