Documentation ¶
Index ¶
- func AuthMiddleware(handler http.Handler, requiredPass string) http.Handler
- func Mux(routes map[string]Handler) *httprouter.Router
- type Client
- type Context
- func (c Context) Check(msg string, err error) error
- func (c Context) Decode(v interface{}) error
- func (c Context) DecodeForm(key string, v interface{}) error
- func (c Context) DecodeParam(param string, v interface{}) error
- func (c Context) Encode(v interface{})
- func (c Context) Error(err error, status int) error
- func (c Context) PathParam(param string) string
- type Handler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthMiddleware ¶
AuthMiddleware enforces HTTP Basic Authentication on the provided handler.
Types ¶
type Client ¶
A Client provides methods for interacting with an API server.
type Context ¶
type Context struct { ResponseWriter http.ResponseWriter Request *http.Request PathParams httprouter.Params }
A Context contains the values relevant to an HTTP handler.
func (Context) Check ¶
Check conditionally writes an error. If err is non-nil, Check prefixes it with msg, writes it to the response body (with status code 500), and returns it. Otherwise it returns nil.
func (Context) Decode ¶
Decode decodes the JSON of the request body into v. If decoding fails, Decode writes an error to the response body and returns it.
func (Context) DecodeForm ¶ added in v0.3.0
DecodeForm decodes the form value with the specified key into v, which must implement one of the following methods:
UnmarshalText([]byte) error LoadString(string) error
The following basic types are also supported:
*int *bool
If decoding fails, DecodeForm writes an error to the response body and returns it. If the form value is empty, no error is returned and v is unchanged.
func (Context) DecodeParam ¶
DecodeParam decodes the specified path parameter into v, which must implement one of the following methods:
UnmarshalText([]byte) error LoadString(string) error
If decoding fails, DecodeParam writes an error to the response body and returns it.
func (Context) Encode ¶
func (c Context) Encode(v interface{})
Encode writes the JSON encoding of v to the response body.