extractors

package
v0.0.0-...-9b21b70 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextValueExtractor

func ContextValueExtractor[T any]() gum.Extractor[T]

ContextValueExtractor returns a gum.Extractor that extracts a value of type T from the context.Context that was previous provided using ProvideContextValue.

Types

type ContentLength

type ContentLength int64

ContentLength is the value of the Content-Length header. Only available if the value requests value is not negative.

type ContentType

type ContentType string

ContentType holds the value of the requests Content-Type header.

type ContextValue

type ContextValue[T any] struct {
	Value T
}

ContextValue uses the type T as the key to lookup a value of type T in the requests context.Context. Use WithContextValue to get a http.Handler middleware that injects a value into the context.Context

func (ContextValue[T]) FromRequest

func (ContextValue[T]) FromRequest(r *http.Request) (ContextValue[T], error)

type Form

type Form struct {
	url.Values
}

Form contains the requests parsed form as url.Values

type Host

type Host string

Host is the value of the Host header

type JSON

type JSON[T any] struct {
	Value T
}

JSON parses the requests body as json

func (JSON[T]) FromRequest

func (JSON[T]) FromRequest(r *http.Request) (JSON[T], error)

type Logger

type Logger struct {
	*slog.Logger
	// contains filtered or unexported fields
}

func (Logger) Close

func (l Logger) Close() error

func (Logger) FromRequest

func (l Logger) FromRequest(r *http.Request) (Logger, error)

type Method

type Method string

Method is the value of the requests Method field, e.g. GET, POST, etc

type Middleware

type Middleware = func(delegate http.Handler) http.Handler

func ProvideContextValue

func ProvideContextValue[T any](value T) Middleware

ProvideContextValue provides a Middleware that injects a value of type T into the requests context. The value can later be extracted by using ContextValue.

type MultipartFormMaxMemory

type MultipartFormMaxMemory int64

type Option

type Option[T any] struct {
	Value T
	IsSet bool
}

Option is similar to Try, it just swallows any error.

func (Option[T]) FromRequest

func (Option[T]) FromRequest(r *http.Request) (Option[T], error)

func (Option[T]) Get

func (o Option[T]) Get() (T, bool)

Get gets the Option value and a boolean flag to test if the value is set.

func (Option[T]) GetOr

func (o Option[T]) GetOr(fallbackValue T) T

GetOr returns the value in this Option if it exists and falls back to the provided fallback value otherwise

func (Option[T]) GetOrZero

func (o Option[T]) GetOrZero() T

GetOrZero calls GetOr with a zero T value

type Query

type Query struct {
	url.Values
}

Query contains the requests query values as url.Values

type RawBody

type RawBody []byte

RawBody is a byte slice holding the requests body.

type Try

type Try[T any] struct {
	Value T
	Error error
}

Try tries to extract a T from the request but will not fail the request processing if extraction fails. A Try has either the Value or the Error field set.

func (Try[T]) FromRequest

func (Try[T]) FromRequest(r *http.Request) (Try[T], error)

func (Try[T]) Get

func (o Try[T]) Get() (T, error)

Get gets the Try value and its error

Jump to

Keyboard shortcuts

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