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 (r Conf) InvalidErrFactory() func(err error) Output
- 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) SetClientErrFactory(f func(err error) Output) *Conf
- func (c *Conf) SetDecodings(decs ...epcoding.Decoding) *Conf
- func (c *Conf) SetEncodings(encs ...epcoding.Encoding) *Conf
- func (r *Conf) SetInvalidErrFactory(f func(err error) Output) *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 InvalidInputError
- 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 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 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) InvalidErrFactory ¶ added in v0.0.6
InvalidErrFactory returns the current invalid input error factory
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) SetInvalidErrFactory ¶ added in v0.0.6
SetInvalidErrFactory configures how invalid input errors are created
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 InvalidErrFactory() func(err error) 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 InvalidInputError ¶ added in v0.0.6
type InvalidInputError struct {
// contains filtered or unexported fields
}
InvalidInputError can be returned to render to write a response that indicates that the server understood the request but didn't accept the parameters
func InvalidInput ¶
func InvalidInput(e error) *InvalidInputError
InvalidInput creates a error that can be returned to indicate that the client needs to check its parameters
func (*InvalidInputError) Error ¶ added in v0.0.6
func (e *InvalidInputError) Error() string
Error implements error interface
func (*InvalidInputError) Unwrap ¶ added in v0.0.6
func (e *InvalidInputError) Unwrap() error
Unwrap returns the wrapped error
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) }
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) 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 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