Skip to content

Commit 49dea4f

Browse files
authored
body parser method (#9)
1 parent 078353d commit 49dea4f

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

context.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,7 @@ func (c *Context) JSON(code int, obj interface{}) ([]byte, error) {
219219

220220
return []byte(jsonBody), nil
221221
}
222+
223+
func (c *Context) BodyParser(v interface{}) error {
224+
return utils.FromJSON(c.RequestCtx.Request.Body(), v)
225+
}

utils/json.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ func ToJSON(v interface{}) (string, error) {
99
}
1010
return string(b), nil
1111
}
12+
13+
func FromJSON(b []byte, v interface{}) error {
14+
return json.Unmarshal(b, v)
15+
}

0 commit comments

Comments
 (0)