Documentation ¶
Index ¶
- func R(w http.ResponseWriter, r *http.Request, v render.Renderer)
- func Unmarshal(r io.Reader, kvs ...KV) (*base.Response, error)
- type ErrResponse
- func Err(message string, code int, kvs ...interface{}) *ErrResponse
- func ErrBadRequest(message string, kvs ...interface{}) *ErrResponse
- func ErrForbidden(message string, kvs ...interface{}) *ErrResponse
- func ErrInternalServer(message string, err error, kvs ...interface{}) *ErrResponse
- func ErrNotFound(message string, kvs ...interface{}) *ErrResponse
- func ErrUnauthorized(message string, kvs ...interface{}) *ErrResponse
- type KV
- type M
- type MsgResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Unmarshal ¶
Unmarshal reads the response and unmarshalls the BaseResponse as well any requested key-value pairs. For example:
var prop = map[string]string api.Unmarshal(resp.Body, api.KV{Key: "prop", Value: &prop})
Values provided in KV.Value MUST be explicit pointers, even if the value is a pointer type, ie maps and slices.
Types ¶
type ErrResponse ¶
ErrResponse is the template for a typical HTTP response for errors
func Err ¶
func Err(message string, code int, kvs ...interface{}) *ErrResponse
Err is a basic error response constructor
func ErrBadRequest ¶
func ErrBadRequest(message string, kvs ...interface{}) *ErrResponse
ErrBadRequest is a shortcut for bad requests
func ErrForbidden ¶
func ErrForbidden(message string, kvs ...interface{}) *ErrResponse
ErrForbidden is a shortcut for forbidden requests
func ErrInternalServer ¶
func ErrInternalServer(message string, err error, kvs ...interface{}) *ErrResponse
ErrInternalServer is a shortcut for internal server errors. It should be accompanied by an actual error.
func ErrNotFound ¶
func ErrNotFound(message string, kvs ...interface{}) *ErrResponse
ErrNotFound is a shortcut for forbidden requests
func ErrUnauthorized ¶
func ErrUnauthorized(message string, kvs ...interface{}) *ErrResponse
ErrUnauthorized is a shortcut for unauthorized requests
type KV ¶
type KV struct { Key string Value interface{} }
KV is used for defining specific values to be unmarshalled from BaseResponse data
type MsgResponse ¶
MsgResponse is the template for a typical HTTP response for messages
func Msg ¶
func Msg(message string, code int, kvs ...interface{}) *MsgResponse
Msg is a shortcut for non-error statuses
func MsgOK ¶
func MsgOK(message string, kvs ...interface{}) *MsgResponse
MsgOK is a shortcut for an ok-status response