Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Convert ¶
func Convert(f HandlerFunc) http.HandlerFunc
Convert converts a HandlerFunc to an http.HandlerFunc.
Types ¶
type CallbackFunc ¶
type CallbackFunc func(error)
CallbackFunc receives the value of errors which occur when the body fails to write to the remote end.
type HandlerFunc ¶
HandlerFunc is an analog of an http.HandlerFunc that returns a response object instead of writing directly to a ResponseWriter.
type Response ¶
type Response interface { // StatusCode retrieves the status code of the response. StatusCode() int // Header retrieves the first value set to this header. Header(header string) string // SetStatusCode sets the status code of the response. SetStatusCode(statusCode int) Response // SetHeader sets the value of this header. SetHeader(header, val string) Response // AddHeader adds another value to this header. AddHeader(header, val string) Response // AddCallback registers a callback to be invoked on after // the entire response body has been written to the client. AddCallback(f CallbackFunc) Response // DecorateWriter wraps a function around the underlying io.Writer // which writes the response body content. DecorateWriter(f WriterDecorator) Response // WriteTo writes the response data to the ResponseWriter. This method // consumes the body content and will panic when called multiple times. WriteTo(w http.ResponseWriter) }
Response wraps a payload returned from an HTTP handler function.
func JSON ¶
func JSON(data interface{}) Response
JSON creates a response with the data serialized as JSON for the body.
func Reconstruct ¶
Reconstruct creates a response from the values returned from Serialize.
func Stream ¶
func Stream(rc io.ReadCloser, configs ...StreamConfigFunc) Response
Stream creates a response that writes the data from the given reader. The reader is closed once all data is consumed, an error is encountered, or the client disconnects.
type StreamConfigFunc ¶
type StreamConfigFunc func(*streamConfig)
StreamConfigFunc is a function used to configure the Stream constructor.
func WithFlush ¶
func WithFlush() StreamConfigFunc
WithFlush instructs Stream to call the writer's Flush method after every successful chunk of data is written.
func WithProgressChan ¶
func WithProgressChan(progress chan<- int) StreamConfigFunc
WithProgressChan instructs Stream to send the number of bytes written to this chan after every successful chunk of data is written. Consumers of this channel should be efficient as this write will block progress. This channel is closed by the WriteTo method.
type WriterDecorator ¶
WriterDecorator returns an io.Writer that writes to the given io.Writer.