Documentation ¶
Index ¶
- Constants
- func Decode(request *http.Request, val interface{}) error
- func IsShutdown(err error) bool
- func NewRequestError(err error, status int) error
- func NewShutdownError(message string) error
- func Respond(ctx context.Context, writer http.ResponseWriter, val interface{}, ...) error
- func RespondError(ctx context.Context, writer http.ResponseWriter, err error) error
- type Error
- type ErrorResponse
- type FieldError
- type Handler
- type Middleware
- type Router
- type Values
Constants ¶
const KeyValues ctxKey = 1
KeyValues is how request values or stored/retrieved.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
Decode reads the body of a HTTP request looking for a JSON document. The body is decoded into the provided value.
If the provided value is a struct then it is checked for validation tags.
func IsShutdown ¶
IsShutdown checks to see if the shutdown error is contained in the specified error value.
func NewRequestError ¶
NewRequestError is used when a know error condition is encountered.
func NewShutdownError ¶
NewShutdownError returns an error that causes the framework to signal a graceful shutdown
func Respond ¶
func Respond(ctx context.Context, writer http.ResponseWriter, val interface{}, statusCode int) error
Respond marshals a value to JSON and sends it to the client.
func RespondError ¶
RespondError knows how to handle errors going out to the client.
Types ¶
type Error ¶
type Error struct { Err error Status int Fields []FieldError }
Error is used to add web information to a request error.
type ErrorResponse ¶
type ErrorResponse struct { Error string `json:"error"` Fields []FieldError `json:"fields,omitempty"` }
ErrorResponse how we respond to clients when something goes wrong.
type FieldError ¶
FieldError is used to indicate an error with a specific request field.
type Middleware ¶
Middleware is a function designed to run some code before and/or after another Handler. It is designed to remove boilerplate or other concerns not direct to any given Handler.
type Router ¶
Router is the entry point for all web applications.
func (*Router) Handler ¶
func (router *Router) Handler(method, pattern string, h Handler, mw ...Middleware)
Handler connects a method and URL pattern to a particular application handler.
func (*Router) ServeHTTP ¶
func (router *Router) ServeHTTP(writer http.ResponseWriter, request *http.Request)
func (*Router) SignalShutdown ¶
func (router *Router) SignalShutdown()
SignalShutdown is used to gracefully shutdown the app when an integrity issue is identified.