mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-22 01:12:16 +08:00
body module
This commit is contained in:
parent
783c7ee9c1
commit
9c90e22b85
30
binding/body.go
Normal file
30
binding/body.go
Normal file
@ -0,0 +1,30 @@
|
||||
package binding
|
||||
|
||||
import "net/url"
|
||||
|
||||
// Body type map[string]interface{}
|
||||
type Body map[string]interface{}
|
||||
|
||||
// ToBody transforms object into Body type.
|
||||
func ToBody(in interface{}) *Body {
|
||||
switch in.(type) {
|
||||
case Body:
|
||||
res := in.(Body)
|
||||
|
||||
return &res
|
||||
case url.Values:
|
||||
result := make(Body)
|
||||
|
||||
for key, value := range in.(url.Values) {
|
||||
if len(value) == 1 {
|
||||
result[key] = value[0]
|
||||
} else {
|
||||
result[key] = value
|
||||
}
|
||||
}
|
||||
|
||||
return &result
|
||||
}
|
||||
|
||||
return new(Body)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user