Documentation ¶
Overview ¶
Package htadaptor provides generic domain logic adaptors for HTTP handlers. Adaptors come in three flavors:
1. UnaryFunc: func(context, inputStruct) (outputStruct, error) 2. NullaryFunc: func(context) (outputStruct, error) 3. VoidFunc: func(context, inputStruct) error
Each input requires implementation of Validatable for safety. Validation errors are decorated with the correct http.StatusUnprocessableEntity status code.
Index ¶
- func Must(h http.Handler, err error) http.Handler
- func NewFastFileSystem(withOptions ...FastFileSystemOption) (_ http.Handler, err error)
- type Decoder
- type Encoder
- type EncoderFunc
- type Error
- type ErrorHandler
- type ErrorHandlerFunc
- type FastFileSystemOption
- func WithDefaultFastFileSystemErrorHandler() FastFileSystemOption
- func WithDefaultFastFileSystemLogger() FastFileSystemOption
- func WithFastFileSystemErrorHandler(e ErrorHandler) FastFileSystemOption
- func WithFastFileSystemErrorHandlerFunc(f func(http.ResponseWriter, *http.Request, error)) FastFileSystemOption
- func WithFastFileSystemFile(path string, contentType string, contents []byte) FastFileSystemOption
- func WithFastFileSystemLogger(l RequestLogger) FastFileSystemOption
- func WithFastFileSystemSlogLogger(l *slog.Logger, successLevel slog.Leveler) FastFileSystemOption
- type FuncType
- type InvalidRequestError
- type NotFoundError
- type NullaryFuncAdaptor
- type Option
- func WithDecoder(d Decoder) Option
- func WithDecoderOptions(withOptions ...decoder.Option) Option
- func WithDefaultDecoder() Option
- func WithDefaultEncoder() Option
- func WithDefaultErrorHandler() Option
- func WithDefaultLogger() Option
- func WithEncoder(e Encoder) Option
- func WithEncoderFunc(f func(http.ResponseWriter, any) error) Option
- func WithErrorHandler(e ErrorHandler) Option
- func WithErrorHandlerFunc(f func(http.ResponseWriter, *http.Request, error)) Option
- func WithHyperTextEncoder(t *template.Template) Option
- func WithLogger(l RequestLogger) Option
- func WithOptions(withOptions ...Option) Option
- func WithSlogLogger(l *slog.Logger, successLevel slog.Leveler) Option
- type RequestLogger
- type RequestLoggerFunc
- type StringExtractor
- type UnaryFuncAdaptor
- type UnaryStringFuncAdaptor
- type Validatable
- type VoidFuncAdaptor
- type VoidStringFuncAdaptor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewFastFileSystem ¶ added in v0.0.3
func NewFastFileSystem(withOptions ...FastFileSystemOption) (_ http.Handler, err error)
Types ¶
type EncoderFunc ¶
type EncoderFunc func(http.ResponseWriter, any) error
func (EncoderFunc) Encode ¶
func (f EncoderFunc) Encode(w http.ResponseWriter, v any) error
type ErrorHandler ¶
type ErrorHandler interface {
HandleError(http.ResponseWriter, *http.Request, error)
}
type ErrorHandlerFunc ¶
type ErrorHandlerFunc func(http.ResponseWriter, *http.Request, error)
func (ErrorHandlerFunc) HandleError ¶
func (f ErrorHandlerFunc) HandleError(w http.ResponseWriter, r *http.Request, err error)
type FastFileSystemOption ¶ added in v0.0.3
type FastFileSystemOption func(*fastFileSystemOptions) error
func WithDefaultFastFileSystemErrorHandler ¶ added in v0.0.3
func WithDefaultFastFileSystemErrorHandler() FastFileSystemOption
func WithDefaultFastFileSystemLogger ¶ added in v0.0.3
func WithDefaultFastFileSystemLogger() FastFileSystemOption
func WithFastFileSystemErrorHandler ¶ added in v0.0.3
func WithFastFileSystemErrorHandler(e ErrorHandler) FastFileSystemOption
func WithFastFileSystemErrorHandlerFunc ¶ added in v0.0.3
func WithFastFileSystemErrorHandlerFunc(f func(http.ResponseWriter, *http.Request, error)) FastFileSystemOption
func WithFastFileSystemFile ¶ added in v0.0.3
func WithFastFileSystemFile( path string, contentType string, contents []byte, ) FastFileSystemOption
func WithFastFileSystemLogger ¶ added in v0.0.3
func WithFastFileSystemLogger(l RequestLogger) FastFileSystemOption
func WithFastFileSystemSlogLogger ¶ added in v0.0.3
func WithFastFileSystemSlogLogger( l *slog.Logger, successLevel slog.Leveler, ) FastFileSystemOption
type InvalidRequestError ¶
type InvalidRequestError struct {
// contains filtered or unexported fields
}
func NewInvalidRequestError ¶
func NewInvalidRequestError(fromError error) *InvalidRequestError
func (*InvalidRequestError) Error ¶
func (e *InvalidRequestError) Error() string
func (*InvalidRequestError) HyperTextStatusCode ¶
func (e *InvalidRequestError) HyperTextStatusCode() int
func (*InvalidRequestError) Unwrap ¶
func (e *InvalidRequestError) Unwrap() error
type NotFoundError ¶ added in v0.0.3
type NotFoundError struct {
// contains filtered or unexported fields
}
func (*NotFoundError) Error ¶ added in v0.0.3
func (e *NotFoundError) Error() string
func (*NotFoundError) HyperTextStatusCode ¶ added in v0.0.3
func (e *NotFoundError) HyperTextStatusCode() int
func (*NotFoundError) LogValue ¶ added in v0.0.3
func (e *NotFoundError) LogValue() slog.Value
type NullaryFuncAdaptor ¶
type NullaryFuncAdaptor[O any] struct { // contains filtered or unexported fields }
func NewNullaryFuncAdaptor ¶
func (*NullaryFuncAdaptor[O]) ServeHTTP ¶
func (a *NullaryFuncAdaptor[O]) ServeHTTP( w http.ResponseWriter, r *http.Request, )
func (*NullaryFuncAdaptor[O]) ServeHyperText ¶
func (a *NullaryFuncAdaptor[O]) ServeHyperText( w http.ResponseWriter, r *http.Request, ) (err error)
type Option ¶
type Option func(*options) error
func WithDecoder ¶
func WithDecoderOptions ¶
func WithDefaultDecoder ¶
func WithDefaultDecoder() Option
func WithDefaultEncoder ¶
func WithDefaultEncoder() Option
func WithDefaultErrorHandler ¶
func WithDefaultErrorHandler() Option
func WithDefaultLogger ¶
func WithDefaultLogger() Option
func WithEncoder ¶
func WithEncoderFunc ¶
func WithEncoderFunc(f func(http.ResponseWriter, any) error) Option
func WithErrorHandler ¶
func WithErrorHandler(e ErrorHandler) Option
func WithErrorHandlerFunc ¶
func WithHyperTextEncoder ¶
func WithLogger ¶
func WithLogger(l RequestLogger) Option
func WithOptions ¶
type RequestLogger ¶ added in v0.0.2
func NewRequestLogger ¶ added in v0.0.2
func NewRequestLogger(logger *slog.Logger, successLevel slog.Leveler) RequestLogger
func NewVoidLogger ¶ added in v0.0.2
func NewVoidLogger() RequestLogger
type RequestLoggerFunc ¶ added in v0.0.2
func (RequestLoggerFunc) LogRequest ¶ added in v0.0.2
func (f RequestLoggerFunc) LogRequest(r *http.Request, err error)
type UnaryFuncAdaptor ¶
type UnaryFuncAdaptor[ T any, V Validatable[T], O any, ] struct { // contains filtered or unexported fields }
func NewUnaryFuncAdaptor ¶
func NewUnaryFuncAdaptor[ T any, V Validatable[T], O any, ]( domainCall func(context.Context, V) (O, error), withOptions ...Option, ) (*UnaryFuncAdaptor[T, V, O], error)
func (*UnaryFuncAdaptor[T, V, O]) ServeHTTP ¶
func (a *UnaryFuncAdaptor[T, V, O]) ServeHTTP( w http.ResponseWriter, r *http.Request, )
func (*UnaryFuncAdaptor[T, V, O]) ServeHyperText ¶
func (a *UnaryFuncAdaptor[T, V, O]) ServeHyperText( w http.ResponseWriter, r *http.Request, ) (err error)
type UnaryStringFuncAdaptor ¶ added in v0.0.2
type UnaryStringFuncAdaptor[O any] struct { // contains filtered or unexported fields }
func NewUnaryStringFuncAdaptor ¶ added in v0.0.2
func NewUnaryStringFuncAdaptor[O any]( domainCall func(context.Context, string) (O, error), stringExtractor StringExtractor, withOptions ...Option, ) (*UnaryStringFuncAdaptor[O], error)
func (*UnaryStringFuncAdaptor[O]) ServeHTTP ¶ added in v0.0.2
func (a *UnaryStringFuncAdaptor[O]) ServeHTTP( w http.ResponseWriter, r *http.Request, )
func (*UnaryStringFuncAdaptor[O]) ServeHyperText ¶ added in v0.0.2
func (a *UnaryStringFuncAdaptor[O]) ServeHyperText( w http.ResponseWriter, r *http.Request, ) (err error)
type Validatable ¶
Validatable constrains a domain request. Validation errors are wrapped as InvalidRequestError by the adapter.
type VoidFuncAdaptor ¶
type VoidFuncAdaptor[ T any, V Validatable[T], ] struct { // contains filtered or unexported fields }
func NewVoidFuncAdaptor ¶
func NewVoidFuncAdaptor[ T any, V Validatable[T], ]( domainCall func(context.Context, V) error, withOptions ...Option, ) (*VoidFuncAdaptor[T, V], error)
func (*VoidFuncAdaptor[T, V]) ServeHTTP ¶
func (a *VoidFuncAdaptor[T, V]) ServeHTTP( w http.ResponseWriter, r *http.Request, )
func (*VoidFuncAdaptor[T, V]) ServeHyperText ¶
func (a *VoidFuncAdaptor[T, V]) ServeHyperText( w http.ResponseWriter, r *http.Request, ) (err error)
type VoidStringFuncAdaptor ¶ added in v0.0.2
type VoidStringFuncAdaptor struct {
// contains filtered or unexported fields
}
func NewVoidStringFuncAdaptor ¶ added in v0.0.2
func NewVoidStringFuncAdaptor( domainCall func(context.Context, string) error, stringExtractor StringExtractor, withOptions ...Option, ) (*VoidStringFuncAdaptor, error)
func (*VoidStringFuncAdaptor) ServeHTTP ¶ added in v0.0.2
func (a *VoidStringFuncAdaptor) ServeHTTP( w http.ResponseWriter, r *http.Request, )
func (*VoidStringFuncAdaptor) ServeHyperText ¶ added in v0.0.2
func (a *VoidStringFuncAdaptor) ServeHyperText( w http.ResponseWriter, r *http.Request, ) (err error)
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package chivalue provides value extractors for Chi Router.
|
Package chivalue provides value extractors for Chi Router. |
chivalues
module
|
|
Package decoder provides configurable HTTP form body decoding that depends on Gorilla's schema package which does not contaminate objects with URL query parameters unlike the standard library.
|
Package decoder provides configurable HTTP form body decoding that depends on Gorilla's schema package which does not contaminate objects with URL query parameters unlike the standard library. |
schema
Package schema fills a struct with form values.
|
Package schema fills a struct with form values. |
examples
|
|
basic
Package main demonstrates routing directly to domain function calls.
|
Package main demonstrates routing directly to domain function calls. |
extract
|
|
chivalues
Module
|
|
TODO: move this into root package.
|
TODO: move this into root package. |
Click to show internal directories.
Click to hide internal directories.