MCPcopy
hub / github.com/gin-gonic/gin / Bind

Function Bind

utils.go:29–44  ·  view source on GitHub ↗

Bind is a helper function for given interface object and returns a Gin middleware.

(val any)

Source from the content-addressed store, hash-verified

27
28// Bind is a helper function for given interface object and returns a Gin middleware.
29func Bind(val any) HandlerFunc {
30 value := reflect.ValueOf(val)
31 if value.Kind() == reflect.Ptr {
32 panic(`Bind struct can not be a pointer. Example:
33 Use: gin.Bind(Struct{}) instead of gin.Bind(&Struct{})
34`)
35 }
36 typ := value.Type()
37
38 return func(c *Context) {
39 obj := reflect.New(typ).Interface()
40 if c.Bind(obj) == nil {
41 c.Set(BindKey, obj)
42 }
43 }
44}
45
46// WrapF is a helper function for wrapping http.HandlerFunc and returns a Gin middleware.
47func WrapF(f http.HandlerFunc) HandlerFunc {

Callers 1

TestBindMiddlewareFunction · 0.85

Calls 3

TypeMethod · 0.80
SetMethod · 0.80
BindMethod · 0.65

Tested by 1

TestBindMiddlewareFunction · 0.68