helpers

package
v0.0.0-...-41c1b6c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2017 License: Apache-2.0 Imports: 6 Imported by: 2

Documentation

Index

Constants

View Source
const HeaderAccept string = "Accept"

HeaderAccept represents the HTTP Accept header.

View Source
const HeaderContentType string = "Content-Type"

HeaderContentType represents the HTTP Content-Type header.

View Source
const HeaderLocation string = "Location"

HeaderLocation represents the HTTP Location header.

Variables

This section is empty.

Functions

func AcceptResource

func AcceptResource(r *http.Request, expected string) (interface{}, error)

AcceptResource ...

func ErrorToHTTPStatus

func ErrorToHTTPStatus(err error) int

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

type MediaType struct {
	Type    string
	Version string
}

MediaType represents a set of fields useful to our HTTP routers.

func NewMediaType

func NewMediaType(requested string) (MediaType, error)

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

type StatusError interface {
	error
	HTTPStatus() int
}

StatusError provides an additional interface method on errors to query an error for a HTTP status code.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL