Documentation ¶
Index ¶
- Constants
- Variables
- func DecodeBody(ctx context.Context, data io.ReadCloser, model interface{}) (err error)
- func DecodeParams(ctx context.Context, dst interface{}, src map[string][]string) (errors schema.MultiError)
- func Respond(ctx context.Context, w http.ResponseWriter, data interface{}, ...)
- func RespondError(ctx context.Context, w http.ResponseWriter, httpStatusCode int, err error)
- func RespondSuccess(ctx context.Context, w http.ResponseWriter, data interface{})
- func ValidationRules() *validator.Validate
- type API
- type BaseHandler
- type ConsumerErrors
- type Handler
- type ResponseErr
- type ResponseError
- type ResponsePropertyError
Constants ¶
View Source
const ( APIKEY string = "api-key" REQUEST_ID_KEY string = "x-request-id" REMOTE_ADDR_KEY string = "remote-address" SESSIONID string = "session" )
Variables ¶
View Source
var ( // ErrBadPayload the error to be returned when a request is malformed ErrBadPayload = errors.New("Malformed json request payload") )
Functions ¶
func DecodeBody ¶
func DecodeBody(ctx context.Context, data io.ReadCloser, model interface{}) (err error)
DecodeBody decodes a json request body into a given struct
func DecodeParams ¶
func Respond ¶
func Respond(ctx context.Context, w http.ResponseWriter, data interface{}, httpStatusCode int, err error)
Respond sends standard json response
func RespondError ¶
RespondError sends a json error response
func RespondSuccess ¶
func RespondSuccess( ctx context.Context, w http.ResponseWriter, data interface{})
RespondSuccess sends a json success response
func ValidationRules ¶
Types ¶
type BaseHandler ¶
type BaseHandler struct { }
BaseHandler is the handler for base api routes
func (*BaseHandler) InitRoutes ¶
func (h *BaseHandler) InitRoutes(ctx context.Context, r *mux.Router)
InitRoutes initializes base (non-versioned) api routes
type ConsumerErrors ¶
type ConsumerErrors struct {
Errors []ResponseError `json:"errors"`
}
type ResponseErr ¶
type ResponseErr interface {
Error() string
}
type ResponseError ¶
type ResponseError struct { Message string `json:"message"` Code string `json:"code"` Properties []ResponsePropertyError `json:"properties"` }
func (ResponseError) Error ¶
func (re ResponseError) Error() string
type ResponsePropertyError ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.