Skip to content

Commit

Permalink
Add MustMarshal (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg authored Oct 4, 2023
1 parent d8927ad commit 5796af6
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 5796af6

Please sign in to comment.