Adds Bind() middleware

This commit is contained in:
Manu Mtz-Almeida 2015-06-12 23:42:54 +02:00
parent 7e7004a224
commit ab447bb188

View File

@ -13,6 +13,18 @@ import (
"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 {
return func(c *Context) {
f(c.Writer, c.Request)