Documentation
¶
Index ¶
- Variables
- func Result[T any](ex *Extractor, key string, converter ResultConverter[T]) T
- func ResultPtr[T any](ex *Extractor, key string, converter ResultConverter[T]) *T
- func ReturnBool(ec *Extractor, key string) *bool
- func ReturnFloat64(ec *Extractor, key string) *float64
- func ReturnInt64(ec *Extractor, key string) *int64
- func ReturnString(ec *Extractor, key string) *string
- func ReturnUint64(ec *Extractor, key string) *uint64
- func WithOptionalKeys(keys ...string) func(*Extractor)
- type Converter
- type DirectReturnType
- type Error
- type ErrorType
- type Extractor
- type FormExtractor
- type MapExtractor
- type QueryExtractor
- type ResultConverter
- type ValueExtractor
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("key not found")
ErrNotFound is an error that is returned when a key is not found
var ErrRequestNil = errors.New("request is nil")
ErrRequestNil is an error that is returned when the request is nil
var ErrRequestParseForm = errors.New("error parsing form")
Functions ¶
func Result ¶
func Result[T any](ex *Extractor, key string, converter ResultConverter[T]) T
Result is a function that extracts a value from the request and converts it to the desired type It offers a simpler API than the With function NOTE: this is a convenience function but is slower than using the With function directly the performance is about on par with the traditional struct+reflection approach
func ResultPtr ¶ added in v1.0.1
func ResultPtr[T any](ex *Extractor, key string, converter ResultConverter[T]) *T
ResultPtr is a function that extracts a value from the request and converts it to the desired type It offers a simpler API than the With function, but returns a pointer to the result instead of the result itself NOTE: this is a convenience function but is slower than using the With function directly the performance is about on par with the traditional struct+reflection approach
func ReturnBool ¶ added in v1.0.2
ReturnBool is a function that returns a bool
func ReturnFloat64 ¶ added in v1.0.2
ReturnFloat64 is a function that returns a float64
func ReturnInt64 ¶ added in v1.0.2
ReturnInt64 is a function that returns an int64
func ReturnString ¶ added in v1.0.2
func ReturnUint64 ¶ added in v1.0.2
ReturnUint64 is a function that returns a uint64
func WithOptionalKeys ¶ added in v1.1.0
Types ¶
type Converter ¶
Converter is a function that takes an Extractor and a key and returns a value and an error
type DirectReturnType ¶ added in v1.1.0
DirectReturnType is a function that takes an Extractor and a key and returns a value this is a more performant alternative to the Result generic.
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error is a custom error type that is used to represent errors that occur during the extraction and conversion of values.
func NewConvertError ¶
NewConvertError creates a new ConvertError.
func NewExtractError ¶
NewExtractError creates a new ExtractError.
func (Error) IsConvertError ¶
IsConvertError returns true if the error is of type ConvertError.
func (Error) IsExtractError ¶
IsExtractError returns true if the error is of type ExtractError.
type Extractor ¶
type Extractor struct {
// contains filtered or unexported fields
}
Extractor is a value extractor that can be used to extract values from a request and type-convert them to the desired type, collecting errors along the way
func Using ¶
func Using(extractor ValueExtractor, options ...func(*Extractor)) *Extractor
Using creates a new Extractor with the given value extractor A value extractor is a function that takes a key and returns a value and an error, if any
func (*Extractor) AddConvertError ¶
AddConvertError adds an error to the chain
func (*Extractor) AddExtractError ¶
AddExtractError adds an error to the chain
func (*Extractor) JoinedErrors ¶
JoinedErrors returns a single error with all the errors JoinedErrors
type FormExtractor ¶
FormExtractor is a value extractor that extracts values from a http request's form
type MapExtractor ¶
MapExtractor is a value extractor that extracts values from a map
type QueryExtractor ¶
QueryExtractor is a value extractor that extracts values from a http request's query parameters
type ResultConverter ¶
ResultConverter defines a wrapped converter with input argument as a reference that returns a converter function. It's intended to be used with the Result function
type ValueExtractor ¶
extractors