Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Codec ¶ added in v0.1.1
type Codec struct {
// contains filtered or unexported fields
}
Codec provides http.Handlers that automatically decode requests and encode responses based on input and output structs
type ErrorHook ¶ added in v0.1.0
type ErrorHook func(err error) (out interface{})
ErrorHook can be provided as an option to be called whenever an error is about to be rendered. The error can be logged or an output type can be returend to customize how the error will be turned into a response.
Multiple error hooks can be configured and the first that returns a non-nil output takes precedence.
The returned output will be subjected to the same hooks that any other output would be.
type ErrorKind ¶ added in v0.1.0
type ErrorKind uint8
const ( OtherError ErrorKind = iota ServerError // unexpected server condition UnacceptableError // no encoder supports what the client accepts UnsupportedError // no decoder supports the content type sent by the client RequestHookError // request hook failed to run DecoderError // decoder failed while decoding EncoderError // encoder failed while encoding )
type Option ¶ added in v0.1.0
type Option interface {
// contains filtered or unexported methods
}
Option configures the codec
func RequestDecoding ¶ added in v0.1.0
RequestDecoding option adds an additional supported request decoding for this Codec
func ResponseEncoding ¶ added in v0.1.0
ResponseEncoding option adds an additional supported response encoding for this Codec
type PeekReadCloser ¶ added in v0.1.0
type PeekReadCloser interface { io.ReadCloser Peek(n int) ([]byte, error) }
PeekReadCloser allows for reading, closing and peeking
func Buffer ¶ added in v0.1.0
func Buffer(rc io.ReadCloser) PeekReadCloser
Buffer the provided ReadCloser so that it is possible to peek into the reader without influencing the next read. Unlike the original ReadCloser this buffered variant might not error immediately when calling Read after Close. Instead it will error once the buffered bytes are completely read.
type RequestHook ¶ added in v0.1.0
RequestHook option allows reading arbitrary properties on the request to decorate the input value before the request body is decoded in the bind.
If an error is returned the bind call will return false and the error will rendered.
type ResponseHook ¶ added in v0.1.0
type ResponseHook func(w http.ResponseWriter, r *http.Request, out interface{})
ResponseHook option provides arbitrary modification to the response header just before is send for the response. It is provided with the output that is currently rendered but if the response is called without using the render method this argument might be nil.
type ResponseWriter ¶ added in v0.1.0
type ResponseWriter interface { Bind(in interface{}) bool Render(outs ...interface{}) Recover() http.ResponseWriter }
ResponseWriter extends the traditional http.ResponseWriter interface with functionality that standardizes input decoding and output enepcoding.
func NewResponse ¶
func NewResponse( w http.ResponseWriter, r *http.Request, reqh []RequestHook, resh []ResponseHook, errh []ErrorHook, decs []epcoding.Decoding, encs []epcoding.Encoding, ) ResponseWriter
NewResponse initializes a ResponseWriter