Documentation ¶
Overview ¶
Package render implements functionality related to response rendering.
Index ¶
- func Error(rw http.ResponseWriter, r *http.Request, err error)
- func JSON(w http.ResponseWriter, r *http.Request, v interface{})
- func JSONStatus(w http.ResponseWriter, r *http.Request, v interface{}, status int)
- func ProtoJSON(w http.ResponseWriter, m proto.Message)
- func ProtoJSONStatus(w http.ResponseWriter, m proto.Message, status int)
- type RenderableError
- type StatusCodedError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Error ¶
func Error(rw http.ResponseWriter, r *http.Request, err error)
Error marshals the JSON representation of err to w. In case err implements RenderableError its own Render method will be called instead.
func JSON ¶
func JSON(w http.ResponseWriter, r *http.Request, v interface{})
JSON is shorthand for JSONStatus(w, v, http.StatusOK).
func JSONStatus ¶
func JSONStatus(w http.ResponseWriter, r *http.Request, v interface{}, status int)
JSONStatus marshals v into w. It additionally sets the status code of w to the given one.
JSONStatus sets the Content-Type of w to application/json unless one is specified.
func ProtoJSON ¶
func ProtoJSON(w http.ResponseWriter, m proto.Message)
ProtoJSON is shorthand for ProtoJSONStatus(w, m, http.StatusOK).
func ProtoJSONStatus ¶
func ProtoJSONStatus(w http.ResponseWriter, m proto.Message, status int)
ProtoJSONStatus writes the given value into the http.ResponseWriter and the given status is written as the status code of the response.
Types ¶
type RenderableError ¶
type RenderableError interface { error Render(http.ResponseWriter, *http.Request) }
RenderableError is the set of errors that implement the basic Render method.
Errors that implement this interface will use their own Render method when being rendered into responses.
type StatusCodedError ¶
StatusCodedError is the set of errors that implement the basic StatusCode function.
Errors that implement this interface will use the code reported by StatusCode as the HTTP response code when being rendered by this package.