Documentation ¶
Index ¶
- Constants
- Variables
- func Error(ctx context.Context, writer http.ResponseWriter, err error)
- func Respond(ctx context.Context, writer http.ResponseWriter, data interface{}, code int)
- func RespondError(ctx context.Context, writer http.ResponseWriter, err error, code int)
- type ContextValues
- type Handler
- type JSONError
- type Middleware
Constants ¶
View Source
const KeyValues ctxKey = 1
KeyValues is how request values or stored/retrieved.
Variables ¶
View Source
var ( // ErrNotAuthorized occurs when the call is not authorized. ErrNotAuthorized = errors.New("Not authorized") // ErrDBNotConfigured occurs when the DB is not initialized. ErrDBNotConfigured = errors.New("DB not initialized") // ErrNotFound is abstracting the mgo not found error. ErrNotFound = errors.New("Entity not found") // ErrInvalidID occurs when an ID is not in a valid form. ErrInvalidID = errors.New("ID is not in it's proper form") // ErrValidation occurs when there are validation errors. ErrValidation = errors.New("Validation errors occurred") // ErrInvalidInput occurs when the input data is invalid ErrInvalidInput = errors.New("Invalid input data") // ErrEntityTooLarge occurs when the input data is invalid ErrEntityTooLarge = errors.New("Request entity too large") )
Functions ¶
func Error ¶
func Error(ctx context.Context, writer http.ResponseWriter, err error)
Error handles all error responses for the API.
func Respond ¶
func Respond(ctx context.Context, writer http.ResponseWriter, data interface{}, code int)
Respond sends JSON to the client. If code is StatusNoContent, v is expected to be nil.
func RespondError ¶
RespondError sends JSON describing the error
Types ¶
type ContextValues ¶
ContextValues struct for context values
type JSONError ¶
type JSONError struct { // The error message //in:body Error string `json:"error"` }
JSONError is the response for errors that occur within the API.
type Middleware ¶
A Middleware is a type that wraps a handler to remove boilerplate or other concerns not direct to any given Handler.
Click to show internal directories.
Click to hide internal directories.