Documentation
¶
Overview ¶
Package extract provides a standard set of most common http.Request value extractors which populate fields of a decoded generic request struct.
The most of the extractors target url.Values because it preserves duplicate fields. This gives the flexibility to a [htadaptor.Decoder] to choose how to handle the duplicates.
Index ¶
- func AreSessionExtractorsLast(extractors ...RequestValueExtractor) bool
- func IsSessionExtractor(extractor any) (ok bool)
- type Association
- type Error
- type Extractor
- func NewCookieValueExtractor(names ...string) (Extractor, error)
- func NewHeaderValueExtractor(headerNames ...string) (Extractor, error)
- func NewHostExtractor() (Extractor, error)
- func NewMethodExtractor(fieldName string) (Extractor, error)
- func NewPathValueExtractor(names ...string) (Extractor, error)
- func NewQueryValueExtractor(headerNames ...string) (Extractor, error)
- func NewRemoteAddressExtractor(fieldName string) (Extractor, error)
- func NewSessionValueExtractor(keys ...string) (Extractor, error)
- func NewUserAgentExtractor(fieldName string) (Extractor, error)
- type ReadLimitError
- type RequestValueExtractor
- type RequestValueExtractorFunc
- type Sequence
- type StringValueExtractor
- type StringValueExtractorFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AreSessionExtractorsLast ¶ added in v0.0.15
func AreSessionExtractorsLast(extractors ...RequestValueExtractor) bool
func IsSessionExtractor ¶ added in v0.0.15
Types ¶
type Association ¶ added in v0.1.0
type Error ¶ added in v0.1.1
type Error uint
Error signals the internal failure of an adaptor operation.
func (Error) HyperTextStatusCode ¶ added in v0.1.1
HyperTextStatusCode satisfies Error interface.
type Extractor ¶
type Extractor interface { RequestValueExtractor StringValueExtractor }
Extractor pulls values from an http.Request for domain function parameters.
func NewCookieValueExtractor ¶
NewCookieValueExtractor is a Extractor extractor that pull out http.Cookie values by name from an http.Request.
func NewHeaderValueExtractor ¶
NewHeaderValueExtractor builds an Extractor that pulls out http.Header values by name from an http.Request.
func NewHostExtractor ¶ added in v0.0.15
NewHostExtractor pulls host name an http.Request.
func NewMethodExtractor ¶ added in v0.1.0
NewMethodExtractor pulls request method from an http.Request.
func NewPathValueExtractor ¶
NewPathValueExtractor is a Extractor extractor that pull out url.URL path values by name from an http.Request.
func NewQueryValueExtractor ¶
NewQueryValueExtractor is a Extractor extractor that pull out url.URL query values by name from an http.Request.
func NewRemoteAddressExtractor ¶ added in v0.0.15
NewRemoteAddressExtractor pulls host name an http.Request.
func NewSessionValueExtractor ¶ added in v0.0.14
NewSessionValueExtractor is a Extractor extractor that pulls out session.Session values by key name from an http.Request context.
To prevent session values from accidental insecure overrides two constraints are enforced:
1. Session value extractors must be at the end of extractor lists. 2. If session value is empty, any other values with the same name are removed.
func NewUserAgentExtractor ¶ added in v0.0.15
NewUserAgentExtractor pulls host name from an http.Request.
type ReadLimitError ¶ added in v0.1.1
type ReadLimitError struct {
// contains filtered or unexported fields
}
ReadLimitError indicates the failure to decode due to request intity containing more bytes than a handler is allowed to consume.
func NewReadLimitError ¶ added in v0.1.1
func NewReadLimitError(limit int) *ReadLimitError
func (*ReadLimitError) Error ¶ added in v0.1.1
func (e *ReadLimitError) Error() string
func (*ReadLimitError) HyperTextStatusCode ¶ added in v0.1.1
func (e *ReadLimitError) HyperTextStatusCode() int
func (*ReadLimitError) LogValue ¶ added in v0.1.1
func (e *ReadLimitError) LogValue() slog.Value
type RequestValueExtractor ¶
RequestValueExtractor pulls url.Values from an http.Request in order to provide a [Decoder] with values to populate domain request struct with.
func Join ¶
func Join(exs ...RequestValueExtractor) RequestValueExtractor
Join unites several extractors into one. Returns <nil> if no extractors are given.
type RequestValueExtractorFunc ¶
RequestValueExtractorFunc provides a wrapper for functional implementation of a RequestValueExtractor.
func (RequestValueExtractorFunc) ExtractRequestValue ¶
RequestValueExtractor satisfies RequestValueExtractor interface for RequestValueExtractorFunc.
type Sequence ¶ added in v0.0.15
type Sequence []RequestValueExtractor
type StringValueExtractor ¶
StringValueExtractor pulls out a string value from an http.Request. It is used primarily for custom implentations of [htadaptor.UnaryStringFuncAdaptor] and [htadaptor.VoidStringFuncAdaptor].
type StringValueExtractorFunc ¶
StringValueExtractorFunc is a convient function type that satisfies [StringValue].
func (StringValueExtractorFunc) ExtractStringValue ¶
func (f StringValueExtractorFunc) ExtractStringValue(r *http.Request) (string, error)
ExtractStringValue satisfies [StringValue] for [StringValueFunc].