Documentation
¶
Index ¶
- func Adapt(mid func(http.Handler) http.Handler) func(Handler) Handler
- func BasicAuth(password string) func(http.Handler) 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) Custom(req, resp interface{})
- 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 Adapt ¶ added in v0.5.0
Adapt turns a http.Handler transformer into a Handler transformer, allowing standard middleware to be applied to individual jape endpoints.
Types ¶
type Client ¶
A Client provides methods for interacting with an API server.
func (*Client) Custom ¶ added in v0.4.0
Custom is a no-op that simply declares the request and response types used by a client method. This allows japecheck to be used on endpoints that do not speak JSON.
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) Custom ¶ added in v0.4.0
func (c Context) Custom(req, resp interface{})
Custom is a no-op that simply declares the request and response types used by a handler. This allows japecheck to be used on endpoints that do not speak JSON.
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.