add MustEncode for package gjson

This commit is contained in:
John Guo 2021-12-26 11:26:36 +08:00
parent b79e4a3ab7
commit 984e5f98f7

View File

@ -25,6 +25,15 @@ func Encode(value interface{}) ([]byte, error) {
return json.Marshal(value)
}
// MustEncode performs as Encode, but it panics if any error occurs.
func MustEncode(value interface{}) []byte {
b, err := Encode(value)
if err != nil {
panic(err)
}
return b
}
// Decode decodes json format `data` to golang variable.
// The parameter `data` can be either bytes or string type.
func Decode(data interface{}) (interface{}, error) {