mirror of https://github.com/gin-gonic/gin.git
Adds Bind() middleware
This commit is contained in:
parent
7e7004a224
commit
ab447bb188
12
utils.go
12
utils.go
|
@ -13,6 +13,18 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const BindKey = "_gin-gonic/gin/bindkey"
|
||||||
|
|
||||||
|
func Bind(val interface{}) HandlerFunc {
|
||||||
|
typ := reflect.ValueOf(val).Type()
|
||||||
|
return func(c *Context) {
|
||||||
|
obj := reflect.New(typ).Interface()
|
||||||
|
if c.Bind(obj) == nil {
|
||||||
|
c.Set(BindKey, obj)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func WrapF(f http.HandlerFunc) HandlerFunc {
|
func WrapF(f http.HandlerFunc) HandlerFunc {
|
||||||
return func(c *Context) {
|
return func(c *Context) {
|
||||||
f(c.Writer, c.Request)
|
f(c.Writer, c.Request)
|
||||||
|
|
Loading…
Reference in New Issue