Adds gin.Bind() usage panic!

This commit is contained in:
Manu Mtz-Almeida 2015-06-13 00:01:02 +02:00
parent ab447bb188
commit 22f118f3b6
1 changed files with 8 additions and 1 deletions

View File

@ -16,7 +16,14 @@ import (
const BindKey = "_gin-gonic/gin/bindkey" const BindKey = "_gin-gonic/gin/bindkey"
func Bind(val interface{}) HandlerFunc { func Bind(val interface{}) HandlerFunc {
typ := reflect.ValueOf(val).Type() value := reflect.ValueOf(val)
if value.Kind() == reflect.Ptr {
panic(`Bind struct can not be a pointer. Example:
Use: gin.Bind(Struct{}) instead of gin.Bind(&Struct{})
`)
}
typ := value.Type()
return func(c *Context) { return func(c *Context) {
obj := reflect.New(typ).Interface() obj := reflect.New(typ).Interface()
if c.Bind(obj) == nil { if c.Bind(obj) == nil {