forked from goffee/core
This commit is contained in:
parent
9d83eed4f3
commit
3d4b3651f2
1 changed files with 16 additions and 0 deletions
16
context.go
16
context.go
|
|
@ -89,6 +89,22 @@ func (c *Context) GetRequesBodyMap() map[string]interface{} {
|
||||||
return dat
|
return dat
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get raw data for file binary
|
||||||
|
func (c *Context) GetRawBody() ([]byte, error) {
|
||||||
|
if c.Request.httpRequest.Body == nil {
|
||||||
|
return nil, errors.New("empty body")
|
||||||
|
}
|
||||||
|
|
||||||
|
defer c.Request.httpRequest.Body.Close()
|
||||||
|
|
||||||
|
data, err := io.ReadAll(c.Request.httpRequest.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return data, nil
|
||||||
|
}
|
||||||
|
|
||||||
// get json body and bind to dest interface
|
// get json body and bind to dest interface
|
||||||
func (c *Context) GetRequesBodyStruct(dest interface{}) error {
|
func (c *Context) GetRequesBodyStruct(dest interface{}) error {
|
||||||
body := c.Request.httpRequest.Body
|
body := c.Request.httpRequest.Body
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue