Skip to content
Myr

header.go

This file

Path

binding/header.go

37 lines · 868 bytes · Go

Last changed by

ci(golangci-lint): update configuration and fix lint issues (#4247)Flc゛before adoptionc4287b1

History of this file

Take it

1// Copyright 2022 Gin Core Team. All rights reserved.2// Use of this source code is governed by a MIT style3// license that can be found in the LICENSE file.45package binding67import (8	"net/http"9	"net/textproto"10	"reflect"11)1213type headerBinding struct{}1415func (headerBinding) Name() string {16	return "header"17}1819func (headerBinding) Bind(req *http.Request, obj any) error {20	if err := mapHeader(obj, req.Header); err != nil {21		return err22	}2324	return validate(obj)25}2627func mapHeader(ptr any, h map[string][]string) error {28	return mappingByPtr(ptr, headerSource(h), "header")29}3031type headerSource map[string][]string3233var _ setter = headerSource(nil)3435func (hs headerSource) TrySet(value reflect.Value, field reflect.StructField, tagValue string, opt setOptions) (bool, error) {36	return setByForm(value, field, hs, textproto.CanonicalMIMEHeaderKey(tagValue), opt)37}