Documentation ¶
Overview ¶
http rendering and binding library, including support for error rendering
Index ¶
- func BindFromRequest(r *http.Request, target interface{}) error
- func BindFromResponse(r *http.Response, target interface{}) error
- func NewRequest(method, u string, data interface{}) (*http.Request, error)
- func RenderErrorResponse(w http.ResponseWriter, err error)
- func RenderResponse(w http.ResponseWriter, status int, data interface{}) error
- func SetErrorRenderer(r Renderer)
- func SetObjectBinder(contentType string, b Binder)
- func SetObjectRenderer(r Renderer)
- func SetTextBinder(b Binder)
- func SetTextRenderer(r Renderer)
- type Binder
- type Renderer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BindFromRequest ¶
Binds data from the request to the given target. Will use a text binder if the target is a string pointer, or an object binder otherwise
func BindFromResponse ¶
Binds data from the request to the given target. Will use a text binder if the target is a string pointer, or an object binder otherwise
func NewRequest ¶
Creates a new HTTP request and renders the given data into it. Will use the configured text renderer for string data or the configured object renderer for any other data
func RenderErrorResponse ¶
func RenderErrorResponse(w http.ResponseWriter, err error)
Renders an error into an HTTP response. Uses JSON formatting by default but can be configured to use any renderer. Will use the status of any HTTP error or InternalServerError(500) if the error is not an http error
func RenderResponse ¶
func RenderResponse(w http.ResponseWriter, status int, data interface{}) error
Renders data from the given data into an HTTP response. Will use the configured text renderer for string data or the configured object renderer for any other data
func SetErrorRenderer ¶
func SetErrorRenderer(r Renderer)
Sets the default renderer for any error responses
func SetObjectBinder ¶
Sets the default binder for any object responses of the given content type
func SetObjectRenderer ¶
func SetObjectRenderer(r Renderer)
Sets the default renderer for any object responses
func SetTextBinder ¶
func SetTextBinder(b Binder)
Sets the default renderer for any plain text responses
func SetTextRenderer ¶
func SetTextRenderer(r Renderer)
Sets the default renderer for any plain text responses
Types ¶
type Binder ¶
type Binder interface { // Binds data from an HTTP request into a destination BindFromRequest(r *http.Request, target interface{}) error // Binds data from an HTTP response into a destination BindFromResponse(r *http.Response, target interface{}) error }
Handles binding data from a source to a destination
type Renderer ¶
type Renderer interface { // Renders data to an HTTP response writer RenderResponse(w http.ResponseWriter, status int, data interface{}) error // Creates a new HTTP request and renders data to the body of the request NewRequest(method, destination string, data interface{}) (*http.Request, error) // Renders an error to an HTTP response RenderErrorResponse(w http.ResponseWriter, err error) }
Renders data from a source to a destination