Documentation ¶
Index ¶
- Constants
- type AdaptSpec
- type HTTPHeader
- func (h *HTTPHeader) Adapt(as *AdaptSpec, te texttemplate.TemplateEngine)
- func (h *HTTPHeader) Add(key, value string)
- func (h *HTTPHeader) AddFrom(src *HTTPHeader)
- func (h *HTTPHeader) AddFromStd(src http.Header)
- func (h *HTTPHeader) Copy() *HTTPHeader
- func (h *HTTPHeader) Del(key string)
- func (h *HTTPHeader) Get(key string) string
- func (h *HTTPHeader) GetAll(key string) []string
- func (h *HTTPHeader) Length() int
- func (h *HTTPHeader) Reset(src http.Header)
- func (h *HTTPHeader) Set(key, value string)
- func (h *HTTPHeader) SetFrom(src *HTTPHeader)
- func (h *HTTPHeader) SetFromStd(src http.Header)
- func (h *HTTPHeader) Std() http.Header
- func (h *HTTPHeader) VisitAll(fn func(key, value string))
- type Validator
- type ValidatorSpec
- type ValueValidator
Constants ¶
const ( // KeyCacheControl is the key of Cache-Control. KeyCacheControl = "Cache-Control" // KeyAcceptEncoding is the key of Accept-Encoding. KeyAcceptEncoding = "Accept-Encoding" // KeyContentEncoding is the key of Content-Encoding. KeyContentEncoding = "Content-Encoding" // KeyContentLength is the key of Content-Length. KeyContentLength = "Content-Length" // KeyVary is the key of Vary. KeyVary = "Vary" // KeyXForwardedFor is the key of X-Forwarded-For. KeyXForwardedFor = "X-Forwarded-For" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AdaptSpec ¶
type AdaptSpec struct { Del []string `yaml:"del" jsonschema:"omitempty,uniqueItems=true"` // NOTE: Set and Add allow empty value. Set map[string]string `yaml:"set" jsonschema:"omitempty"` Add map[string]string `yaml:"add" jsonschema:"omitempty"` }
AdaptSpec describes rules for adapting.
type HTTPHeader ¶
type HTTPHeader struct {
// contains filtered or unexported fields
}
HTTPHeader is the wrapper of http.Header with more abilities.
func (*HTTPHeader) Adapt ¶
func (h *HTTPHeader) Adapt(as *AdaptSpec, te texttemplate.TemplateEngine)
Adapt adapts HTTPHeader according to AdaptSpec. Using templateEngine if value contain any valid template
func (*HTTPHeader) AddFrom ¶
func (h *HTTPHeader) AddFrom(src *HTTPHeader)
AddFrom adds values from another HTTPHeader.
func (*HTTPHeader) AddFromStd ¶
func (h *HTTPHeader) AddFromStd(src http.Header)
AddFromStd wraps AddFrom by replacing the parameter type *HTTPHeader with standard http.Header.
func (*HTTPHeader) Copy ¶
func (h *HTTPHeader) Copy() *HTTPHeader
Copy copies HTTPHeader to a whole new HTTPHeader.
func (*HTTPHeader) Del ¶
func (h *HTTPHeader) Del(key string)
Del deletes the key value pair by the key.
func (*HTTPHeader) Get ¶
func (h *HTTPHeader) Get(key string) string
Get gets the FIRST value by the key.
func (*HTTPHeader) GetAll ¶
func (h *HTTPHeader) GetAll(key string) []string
GetAll gets all values of the key.
func (*HTTPHeader) Length ¶ added in v1.3.2
func (h *HTTPHeader) Length() int
Length returns the length of the header in serialized format
func (*HTTPHeader) Reset ¶
func (h *HTTPHeader) Reset(src http.Header)
Reset resets internal src http.Header.
func (*HTTPHeader) Set ¶
func (h *HTTPHeader) Set(key, value string)
Set the key value pair of headers.
func (*HTTPHeader) SetFrom ¶
func (h *HTTPHeader) SetFrom(src *HTTPHeader)
SetFrom sets values from another HTTPHeader.
func (*HTTPHeader) SetFromStd ¶
func (h *HTTPHeader) SetFromStd(src http.Header)
SetFromStd wraps Setfrom by replacing the parameter type *HTTPHeader with standard http.Header.
func (*HTTPHeader) Std ¶
func (h *HTTPHeader) Std() http.Header
Std returns internal Header of standard library.
func (*HTTPHeader) VisitAll ¶
func (h *HTTPHeader) VisitAll(fn func(key, value string))
VisitAll call fn with every key value pair.
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator is the entity standing for all operations to HTTPHeader.
func NewValidator ¶
func NewValidator(spec *ValidatorSpec) *Validator
NewValidator creates a validator.
func (Validator) Validate ¶
func (v Validator) Validate(h *HTTPHeader) error
Validate validates HTTPHeader by the Validator.
type ValidatorSpec ¶
type ValidatorSpec map[string]*ValueValidator
ValidatorSpec describes Validator
type ValueValidator ¶
type ValueValidator struct { // NOTE: It allows empty value. Values []string `yaml:"values" jsonschema:"omitempty,uniqueItems=true"` Regexp string `yaml:"regexp" jsonschema:"omitempty,format=regexp"` // contains filtered or unexported fields }
ValueValidator is the entity to validate value.
func (ValueValidator) Validate ¶
func (vv ValueValidator) Validate() error
Validate validates ValueValidator.