Documentation
¶
Index ¶
- Variables
- func Decoding(ctx context.Context) (dec epcoding.Decoding)
- func Encoding(ctx context.Context) (enc epcoding.Encoding)
- func Language(ctx context.Context) (s string)
- func Negotiate(cfg ConfReader, req *http.Request) *http.Request
- type AppError
- type CheckerInput
- type Conf
- func (r Conf) AppErrFactory() func(err *AppError) Output
- func (r Conf) ClientErrFactory() func(err error) Output
- func (c Conf) Copy() (cc *Conf)
- func (c Conf) Decodings() []epcoding.Decoding
- func (c Conf) Encodings() []epcoding.Encoding
- func (c Conf) Handler(ep Endpoint) *Handler
- func (c Conf) HandlerFunc(epf EndpointFunc) *Handler
- func (c Conf) Languages() []string
- func (c Conf) Logger() Logger
- func (c Conf) QueryDecoder() epcoding.URLValuesDecoder
- func (r Conf) ServerErrFactory() func(err error) Output
- func (r *Conf) SetAppErrFactory(f func(err *AppError) Output) *Conf
- func (r *Conf) SetClientErrFactory(f func(err error) Output) *Conf
- func (c *Conf) SetDecodings(decs ...epcoding.Decoding) *Conf
- func (c *Conf) SetEncodings(encs ...epcoding.Encoding) *Conf
- func (c *Conf) SetLanguages(langs ...string) *Conf
- func (c *Conf) SetLogger(l Logger) *Conf
- func (c *Conf) SetQueryDecoder(d epcoding.URLValuesDecoder) *Conf
- func (r *Conf) SetServerErrFactory(f func(err error) Output) *Conf
- func (c *Conf) SetValidator(v Validator) *Conf
- func (c Conf) Validator() Validator
- func (c *Conf) WithDecoding(decs ...epcoding.Decoding) *Conf
- func (c *Conf) WithEncoding(encs ...epcoding.Encoding) *Conf
- func (c *Conf) WithLanguage(langs ...string) *Conf
- type ConfReader
- type Endpoint
- type EndpointFunc
- type Handler
- type HeaderOutput
- type Input
- type Logger
- type NopLogger
- type Output
- type Reader
- type ReaderInput
- type Response
- func (r *Response) Bind(in Input) (ok bool)
- func (r *Response) Error() error
- func (r *Response) Header() http.Header
- func (r *Response) RecoverRender()
- func (r *Response) Render(out Output, err error)
- func (r *Response) Validate(in Input) (verr error)
- func (r *Response) Write(b []byte) (int, error)
- func (r *Response) WriteHeader(statusCode int)
- type StatusCreated
- type StatusNoContent
- type StatusRedirect
- type StdLogger
- type Validator
Constants ¶
This section is empty.
Variables ¶
var ( // SkipEncode can be retured by the output head to prevent any further // decoding SkipEncode = errors.New("skip encode") )
Functions ¶
func Decoding ¶
Decoding will return the request decoding that was determined based on request headers and MIME sniffing. This will only be empty if the server didn't configure any decodings.
func Encoding ¶
Encoding will return the response encoding as negotiated with the client. This will only be empty if the server didn't specify any supported encodings
Types ¶
type AppError ¶ added in v0.0.7
AppError is an application specific error that can be returned by application code to trigger the rendering of error output with a specific status code.
func Error ¶ added in v0.0.7
Error will create an AppError with at most 1 wrapped error. If the no error is provided the resulting output will show the default http status message for the provided code.
func Errorf ¶ added in v0.0.7
Errorf will create a new AppError that wraps a new formatted error message. The f string may contain %w to wrap an error.
type CheckerInput ¶
CheckerInput can be implemented by Inputs to allow them to validate themselves
type Conf ¶
type Conf struct {
// contains filtered or unexported fields
}
Conf builds endpoint configuration
func (Conf) AppErrFactory ¶ added in v0.0.7
AppErrFactory returns the current invalid input error factory
func (Conf) ClientErrFactory ¶
ClientErrFactory returns the current client error factory
func (Conf) Decodings ¶
func (c Conf) Decodings() []epcoding.Decoding
Decodings returns the configured input decodings
func (Conf) Encodings ¶
func (c Conf) Encodings() []epcoding.Encoding
Encodings returns the configured output encodings
func (Conf) HandlerFunc ¶
func (c Conf) HandlerFunc(epf EndpointFunc) *Handler
HandlerFunc will copy the configuration the func as a handler
func (Conf) QueryDecoder ¶
func (c Conf) QueryDecoder() epcoding.URLValuesDecoder
QueryDecoder configures the query to be decoded into the input struct
func (Conf) ServerErrFactory ¶
ServerErrFactory returns the configured factory for server errors
func (*Conf) SetAppErrFactory ¶ added in v0.0.7
SetAppErrFactory configures how invalid input errors are created
func (*Conf) SetClientErrFactory ¶
SetClientErrFactory configures how client error outputs are created
func (*Conf) SetDecodings ¶
func (*Conf) SetEncodings ¶
func (*Conf) SetLanguages ¶
func (*Conf) SetQueryDecoder ¶
func (*Conf) SetServerErrFactory ¶
SetServerErrFactory configures a factory for the creation of server error outputs
func (*Conf) SetValidator ¶
func (*Conf) WithDecoding ¶
func (*Conf) WithEncoding ¶
func (*Conf) WithLanguage ¶
type ConfReader ¶
type ConfReader interface { Encodings() []epcoding.Encoding Decodings() []epcoding.Decoding Languages() []string Validator() Validator Logger() Logger QueryDecoder() epcoding.URLValuesDecoder ServerErrFactory() func(err error) Output ClientErrFactory() func(err error) Output AppErrFactory() func(err *AppError) Output }
type EndpointFunc ¶
EndpointFunc implements endpoint by providng just the Handle func
type Handler ¶
type Handler struct { *Conf // contains filtered or unexported fields }
Handler handles http for certain endpoint
type HeaderOutput ¶
HeaderOutput can be optionally implementedd by outputs to customize the response headers
type Input ¶
type Input interface{}
Input describes what is read from a request as input to the endpoint.
type Logger ¶ added in v0.0.6
type Logger interface { // LogServerErrRender is called when the response will render a server error LogServerErrRender(err error) // LogClientErrRender is called when the response will render a client error LogClientErrRender(err error) // LogAppErrRender is called when the response will be a rendered app errror LogAppErrRender(err *AppError) }
Logger interface may be implemented to allow the endpoints to provide feedback in what ever way is preferred
type NopLogger ¶ added in v0.0.6
type NopLogger struct{}
NopLogger is can be provided to disable logging
func (NopLogger) LogAppErrRender ¶ added in v0.0.7
func (NopLogger) LogClientErrRender ¶ added in v0.0.6
func (NopLogger) LogServerErrRender ¶ added in v0.0.6
type Output ¶
type Output interface{}
An Output represents one item that results from the endpoint is will be send as the response back to the client.
type Reader ¶
Reader is a buffered reader that keeps track of the number of bytes that have been read.
func NewReader ¶
func NewReader(r io.ReadCloser) *Reader
NewReader turns an unbuffered reader into a buffered read that keeps track of reading progress. The buffer size is 512 bytes to allow MIME sniffing of the readers content
type ReaderInput ¶
ReaderInput is an input that may optionally be implemented by inputs to indicate that it has custom logic for reading the request.
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response is an http.ResponseWriter implementation that comes with a host of untility method for common tasks in http handling.
func NewResponse ¶
func NewResponse( wr http.ResponseWriter, req *http.Request, cfg ConfReader, ) (res *Response)
NewResponse initializes a new Response
func (*Response) Error ¶
Error will return any server, client or validation error that was encountered while formulating the response.
func (*Response) RecoverRender ¶ added in v0.0.6
func (r *Response) RecoverRender()
RecoverRender allows the response to recover from a panic in the stack and render an internal server error.
func (*Response) Render ¶
Render will assert the provided error and earlier errors and provide appropriate feedback in the response. If 'err' is not the same error as returned by Validate() it will be handled as a server error.
func (*Response) Validate ¶
Validate will validate the input and return any error. It will first use any struct validator first before using the input's check method.
func (*Response) WriteHeader ¶
WriteHeader implements the http.ResponseWriter's "WriteHeader" method
type StatusCreated ¶ added in v0.0.7
type StatusCreated struct {
// contains filtered or unexported fields
}
StatusCreated can be embedded to automatically set the setatus code to 201 when it is rendered as output. If SetLocation is called the Location header will also be set.
func (StatusCreated) Head ¶ added in v0.0.7
func (s StatusCreated) Head(w http.ResponseWriter, r *http.Request) error
func (*StatusCreated) SetLocation ¶ added in v0.0.7
func (s *StatusCreated) SetLocation(l string)
type StatusNoContent ¶ added in v0.0.7
type StatusNoContent struct{}
StatusNoContent can be embedded to automatically set the response status code to 204 and prevent any body from being returned.
func (StatusNoContent) Head ¶ added in v0.0.7
func (s StatusNoContent) Head(w http.ResponseWriter, r *http.Request) error
type StatusRedirect ¶ added in v0.0.7
type StatusRedirect struct {
// contains filtered or unexported fields
}
StatusRedirect can be embedded to render a redirect using http.Redirect. It will only do so if SetRedirect is called with a non-empty string.
func (StatusRedirect) Head ¶ added in v0.0.7
func (s StatusRedirect) Head(w http.ResponseWriter, r *http.Request) (err error)
func (*StatusRedirect) SetRedirect ¶ added in v0.0.7
func (s *StatusRedirect) SetRedirect(l string, code ...int)
SetRedirect will cause the response to be a redirect. By default it will be a '303 See Other' redirect unless the code is used set it to another 3xx status code.
type StdLogger ¶ added in v0.0.6
type StdLogger struct {
// contains filtered or unexported fields
}
StdLogger creates a logger using the standard library logging package
func NewStdLogger ¶ added in v0.0.6
NewStdLogger inits a new standard library logger. If logs is nil it will use the global logs.* methods for printing