github.com/songzhibin97/gkit@v1.2.13/tools/bind/header.go (about) 1 package bind 2 3 import ( 4 "net/http" 5 "net/textproto" 6 "reflect" 7 ) 8 9 type headerBinding struct{} 10 11 func (headerBinding) Name() string { 12 return "header" 13 } 14 15 func (headerBinding) Bind(req *http.Request, obj interface{}) error { 16 return mapHeader(obj, req.Header) 17 } 18 19 func mapHeader(ptr interface{}, h map[string][]string) error { 20 return mappingByPtr(ptr, headerSource(h), "header") 21 } 22 23 type headerSource map[string][]string 24 25 var _ setter = headerSource(nil) 26 27 func (hs headerSource) TrySet(value reflect.Value, field reflect.StructField, tagValue string, opt setOptions) (isSetted bool, err error) { 28 return setByForm(value, field, hs, textproto.CanonicalMIMEHeaderKey(tagValue), opt) 29 }