diff --git a/context.go b/context.go index d678e91..d41503f 100644 --- a/context.go +++ b/context.go @@ -219,3 +219,7 @@ func (c *Context) JSON(code int, obj interface{}) ([]byte, error) { return []byte(jsonBody), nil } + +func (c *Context) BodyParser(v interface{}) error { + return utils.FromJSON(c.RequestCtx.Request.Body(), v) +} diff --git a/utils/json.go b/utils/json.go index 6dd1d9b..9179c70 100644 --- a/utils/json.go +++ b/utils/json.go @@ -9,3 +9,7 @@ func ToJSON(v interface{}) (string, error) { } return string(b), nil } + +func FromJSON(b []byte, v interface{}) error { + return json.Unmarshal(b, v) +}