Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bind ¶
func Bind(w http.ResponseWriter, r *http.Request, target interface{}) (ok bool)
Bind parses and bind the request body to the given target Bind wil also validates the received data with a validator instance. If the data does not match the target constraints, an ErrorResponse will be sent back. See gopkg.in/go-playground/validator.v9 for more informations about data validation.
func DataResponse ¶
func DataResponse(w http.ResponseWriter, status int, data interface{})
func ErrorResponse ¶
func ErrorResponse(w http.ResponseWriter, status int, code ErrorCode, data interface{})
Types ¶
type Error ¶
type Error struct { Code ErrorCode `json:"code"` Data interface{} `json:"data,omitempty"` }
Error is a JSON encoded error
type ErrorCode ¶
type ErrorCode string
const ( ErrCodeMalformedRequest ErrorCode = "malformed-request" ErrCodeInvalidRequest ErrorCode = "invalid-request" ErrCodeInvalidFieldValue ErrorCode = "invalid-field-value" ErrCodeNotFound ErrorCode = "not-found" ErrCodeUnknownError ErrorCode = "unknown-error" ErrCodeForbidden ErrorCode = "forbidden" )
Click to show internal directories.
Click to hide internal directories.