Documentation
¶
Index ¶
- Variables
- func ContextHook(out Output, w http.ResponseWriter, r *http.Request) error
- 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
- func StatusCreatedHook(out Output, w http.ResponseWriter, r *http.Request) error
- func StatusNoContentHook(out Output, w http.ResponseWriter, r *http.Request) error
- func StatusRedirectHook(out Output, w http.ResponseWriter, r *http.Request) error
- type CheckerInput
- type Conf
- 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) Hooks() []Hook
- func (c Conf) Languages() []string
- func (c Conf) OnErrorRender() func(isClient bool, err error) Output
- func (c Conf) QueryDecoder() epcoding.URLValuesDecoder
- 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) SetOnErrorRender(h func(isClient bool, err error) Output) *Conf
- func (c *Conf) SetQueryDecoder(d epcoding.URLValuesDecoder) *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) WithHook(hooks ...Hook) *Conf
- func (c *Conf) WithLanguage(langs ...string) *Conf
- type ConfReader
- type Contextual
- type Endpoint
- type EndpointFunc
- type Handler
- type Hook
- 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) 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 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 ContextHook ¶ added in v0.0.15
ContextHook will contextual outputs to be provided with a context
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
func Language ¶
Language will return the language as negotiated with the client. This will only be empty if the server didn't provide any languages
func Negotiate ¶
func Negotiate(cfg ConfReader, req *http.Request) *http.Request
Negotiate will look at the requests' headers and set context values for encoding, decoding and language.
func StatusCreatedHook ¶ added in v0.0.15
StatusCreatedHook allow outputs to be rendered as created responses
func StatusNoContentHook ¶ added in v0.0.15
StatusNoContentHook allow outputs to be rendered as created responses
func StatusRedirectHook ¶ added in v0.0.15
StatusRedirectHook allow redirect outputs to be rendered correctly easily
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) 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) OnErrorRender ¶ added in v0.0.16
func (Conf) QueryDecoder ¶
func (c Conf) QueryDecoder() epcoding.URLValuesDecoder
QueryDecoder configures the query to be decoded into the input struct
func (*Conf) SetDecodings ¶
func (*Conf) SetEncodings ¶
func (*Conf) SetLanguages ¶
func (*Conf) SetOnErrorRender ¶ added in v0.0.16
OnErrorRender determines how the response rendering handles error
func (*Conf) SetQueryDecoder ¶
func (*Conf) SetValidator ¶
func (*Conf) WithDecoding ¶
func (*Conf) WithEncoding ¶
func (*Conf) WithLanguage ¶
type ConfReader ¶
type Contextual ¶ added in v0.0.15
type Contextual struct {
// contains filtered or unexported fields
}
Contextual can be embedded in an output type to cause the request context to be injected
func (Contextual) Ctx ¶ added in v0.0.15
func (out Contextual) Ctx() context.Context
Ctx returns the injected context
func (*Contextual) SetContext ¶ added in v0.0.15
func (out *Contextual) SetContext(ctx context.Context)
SetContext is called to inject the request context
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 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 app 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 status code to 201 when it is rendered as output. If SetLocation is called the Location header will also be set.
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.
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) 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.