Documentation ¶
Index ¶
- Constants
- func AcceptResource(r *http.Request, expected string) (interface{}, error)
- func ErrorToHTTPStatus(err error) int
- func RenderError(w http.ResponseWriter, err error)
- func RenderLocation(w http.ResponseWriter, status int, location string) error
- func RenderResource(w http.ResponseWriter, r *http.Request, expected string, status int, ...) error
- type ErrorHandler
- type HTTPStatusError
- type MediaType
- type StatusError
Constants ¶
const HeaderAccept string = "Accept"
HeaderAccept represents the HTTP Accept header.
const HeaderContentType string = "Content-Type"
HeaderContentType represents the HTTP Content-Type header.
const HeaderLocation string = "Location"
HeaderLocation represents the HTTP Location header.
Variables ¶
This section is empty.
Functions ¶
func AcceptResource ¶
AcceptResource ...
func ErrorToHTTPStatus ¶
ErrorToHTTPStatus converts an error into a proper HTTP status code for use in our routers. It is a fallback for errors produced in libraries we don't control which utilize error strings to denote their type of behavior. Our primary case at this point is the mgo 'not found' error.
func RenderError ¶
func RenderError(w http.ResponseWriter, err error)
RenderError writes the error and associated error HTTP status code to the response.
func RenderLocation ¶
func RenderLocation(w http.ResponseWriter, status int, location string) error
RenderLocation writes the location and associated status code to the response.
func RenderResource ¶
func RenderResource(w http.ResponseWriter, r *http.Request, expected string, status int, object interface{}) error
RenderResource accepts HTTP request/response objects as well as an intended HTTP status code, expected HTTP Content-Type, and a resource object to render.
Types ¶
type ErrorHandler ¶
type ErrorHandler func(http.ResponseWriter, *http.Request) error
ErrorHandler provides an error handling capable HTTP handler.
func (ErrorHandler) ServeHTTP ¶
func (handler ErrorHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements the standard HTTP handler interface and handles ErrorHandler based handler functions.
type HTTPStatusError ¶
type HTTPStatusError struct {
// contains filtered or unexported fields
}
HTTPStatusError implements the StatusError interface to provide HTTP status aware errors.
func NewHTTPStatusError ¶
func NewHTTPStatusError(status int, format string, a ...interface{}) HTTPStatusError
NewHTTPStatusError returns a properly configured HTTPStatusError object.
func (HTTPStatusError) Error ¶
func (err HTTPStatusError) Error() string
Error is the implementation of the standard library error interface.
func (HTTPStatusError) HTTPStatus ¶
func (err HTTPStatusError) HTTPStatus() int
HTTPStatus returns the configured status code for use in HTTP responses.
type MediaType ¶
MediaType represents a set of fields useful to our HTTP routers.
func NewMediaType ¶
NewMediaType parses an HTTP Accept/Content-Type header and returns a MediaType struct with key fields extracted for use in our HTTP routers.
type StatusError ¶
StatusError provides an additional interface method on errors to query an error for a HTTP status code.