Skip to content

Commit

Permalink
body parser method (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
2hmad authored Apr 13, 2023
1 parent 078353d commit 49dea4f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 4 additions & 0 deletions utils/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 49dea4f

Please sign in to comment.