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 CheckerInput
- type Conf
- 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) QueryDecoder() epcoding.URLValuesDecoder
- func (r Conf) ServerErrFactory() func(err error) Output
- 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) 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 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) Render(err error, out Output)
- func (r *Response) Validate(in Input) (verr error)
- func (r *Response) Write(b []byte) (int, error)
- func (r *Response) WriteHeader(statusCode int)
- type Validator
Constants ¶
This section is empty.
Variables ¶
var ( // InvalidInput can be used explicitely to render the response as an invalid // input instead of an server error InvalidInput = errors.New("invalid input") )
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 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) 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) 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 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 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) 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