Documentation
¶
Overview ¶
Package respond provides low touch API for sending HTTP responses.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func With ¶
func With(w http.ResponseWriter, status int, data []byte) error
With sends the headers with the provided status then writes the data on the provided http.ResponseWriter.
If also overwrites the Content-Length header to the length of data byte slice provided.
If provided http.ResponseWriter errors while writing the response then a non-nil error is returned wrapping the original error.
func WithJSON ¶
func WithJSON(w http.ResponseWriter, status int, data interface{}) error
WithJSON also sends the headers with the provided status then writes the data on the provided http.ResponseWriter after marshalling the data into json.
It also overwrites the the Content-Type header to application/json, if the provided data is non-nil.
If marshalling of the provided data fails or the http.ResponseWriter errors while writing the response then a non-nil error is returned wrapping the original error.
Types ¶
This section is empty.