mirror of
https://codeberg.org/superseriousbusiness/gotosocial.git
synced 2024-12-24 09:58:17 +03:00
98263a7de6
* start fixing up tests * fix up tests + automate with drone * fiddle with linting * messing about with drone.yml * some more fiddling * hmmm * add cache * add vendor directory * verbose * ci updates * update some little things * update sig
34 lines
726 B
Go
34 lines
726 B
Go
package binding
|
|
|
|
import (
|
|
"net/http"
|
|
"net/textproto"
|
|
"reflect"
|
|
)
|
|
|
|
type headerBinding struct{}
|
|
|
|
func (headerBinding) Name() string {
|
|
return "header"
|
|
}
|
|
|
|
func (headerBinding) Bind(req *http.Request, obj interface{}) error {
|
|
|
|
if err := mapHeader(obj, req.Header); err != nil {
|
|
return err
|
|
}
|
|
|
|
return validate(obj)
|
|
}
|
|
|
|
func mapHeader(ptr interface{}, h map[string][]string) error {
|
|
return mappingByPtr(ptr, headerSource(h), "header")
|
|
}
|
|
|
|
type headerSource map[string][]string
|
|
|
|
var _ setter = headerSource(nil)
|
|
|
|
func (hs headerSource) TrySet(value reflect.Value, field reflect.StructField, tagValue string, opt setOptions) (bool, error) {
|
|
return setByForm(value, field, hs, textproto.CanonicalMIMEHeaderKey(tagValue), opt)
|
|
}
|