github.com/songzhibin97/gkit@v1.2.13/tools/bind/all.go (about) 1 package bind 2 3 import ( 4 "net/http" 5 6 "github.com/songzhibin97/gkit/options" 7 ) 8 9 type all struct { 10 contentType string 11 selectorParse []Binding 12 } 13 14 func (*all) Name() string { 15 return "all" 16 } 17 18 func (a *all) Bind(req *http.Request, obj interface{}) error { 19 for _, binding := range a.selectorParse { 20 if err := binding.Bind(req, obj); err != nil { 21 return err 22 } 23 } 24 return validate(obj) 25 } 26 27 func CreateBindAll(contentType string, option ...options.Option) Binding { 28 a := &all{contentType: contentType, selectorParse: DefaultParse(contentType)} 29 for _, o := range option { 30 o(a) 31 } 32 return a 33 }