extract

package
v0.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 8 Imported by: 0

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

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

func IsSessionExtractor(extractor any) (ok bool)

Types

type Association added in v0.1.0

type Association struct {
	RequestName string
	SchemaName  string
}

type Error added in v0.1.1

type Error uint

Error signals the internal failure of an adaptor operation.

const (
	ErrUnknown Error = iota
	ErrNoStringValue
	ErrUnsupportedMediaType
)

func (Error) Error added in v0.1.1

func (e Error) Error() string

Error satisfies [error] interface.

func (Error) HyperTextStatusCode added in v0.1.1

func (e Error) HyperTextStatusCode() int

HyperTextStatusCode satisfies Error interface.

type Extractor

type Extractor interface {
	RequestValueExtractor
	StringValueExtractor
}

Extractor pulls values from an http.Request for domain function parameters.

func NewCookieValueExtractor

func NewCookieValueExtractor(names ...string) (Extractor, error)

NewCookieValueExtractor is a Extractor extractor that pull out http.Cookie values by name from an http.Request.

func NewHeaderValueExtractor

func NewHeaderValueExtractor(headerNames ...string) (Extractor, error)

NewHeaderValueExtractor builds an Extractor that pulls out http.Header values by name from an http.Request.

func NewHostExtractor added in v0.0.15

func NewHostExtractor() (Extractor, error)

NewHostExtractor pulls host name an http.Request.

func NewMethodExtractor added in v0.1.0

func NewMethodExtractor(fieldName string) (Extractor, error)

NewMethodExtractor pulls request method from an http.Request.

func NewPathValueExtractor

func NewPathValueExtractor(names ...string) (Extractor, error)

NewPathValueExtractor is a Extractor extractor that pull out url.URL path values by name from an http.Request.

func NewQueryValueExtractor

func NewQueryValueExtractor(headerNames ...string) (Extractor, error)

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

func NewRemoteAddressExtractor(fieldName string) (Extractor, error)

NewRemoteAddressExtractor pulls host name an http.Request.

func NewSessionValueExtractor added in v0.0.14

func NewSessionValueExtractor(keys ...string) (Extractor, error)

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

func NewUserAgentExtractor(fieldName string) (Extractor, error)

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

type RequestValueExtractor interface {
	ExtractRequestValue(url.Values, *http.Request) error
}

RequestValueExtractor pulls url.Values from an http.Request in order to provide a [Decoder] with values to populate domain request struct with.

func Join

Join unites several extractors into one. Returns <nil> if no extractors are given.

type RequestValueExtractorFunc

type RequestValueExtractorFunc func(url.Values, *http.Request) error

RequestValueExtractorFunc provides a wrapper for functional implementation of a RequestValueExtractor.

func (RequestValueExtractorFunc) ExtractRequestValue

func (f RequestValueExtractorFunc) ExtractRequestValue(vs url.Values, r *http.Request) error

RequestValueExtractor satisfies RequestValueExtractor interface for RequestValueExtractorFunc.

type Sequence added in v0.0.15

type Sequence []RequestValueExtractor

func (Sequence) ExtractRequestValue added in v0.0.15

func (s Sequence) ExtractRequestValue(vs url.Values, r *http.Request) (err error)

type StringValueExtractor

type StringValueExtractor interface {
	ExtractStringValue(*http.Request) (string, error)
}

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

type StringValueExtractorFunc func(*http.Request) (string, error)

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].

Directories

Path Synopsis
chivalues module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL