Documentation ¶
Index ¶
- Variables
- func EasyHandle(method string, ...) func(http.ResponseWriter, *http.Request)
- func GetKeyByValue(mapping map[string]string, value, def string) string
- func MapFields(mapping map[string]string, unmappedObj interface{}) error
- func MultiObjectResp(objectType string, attrs []map[string]interface{}) map[string]interface{}
- func NewAPIError(status int, msg string, errors Errors) error
- func NewMultiAPIErr(status int, message string, errs []Error) error
- func NewSingleAPIErr(status int, code, field, message string, links map[string]string) error
- func SingleObjectResp(objectType string, attr map[string]interface{}) map[string]interface{}
- func UnMapFields(mapping map[string]string, mappedObj interface{}) error
- type APIError
- type Error
- type Errors
Constants ¶
This section is empty.
Variables ¶
var ( // CodeInvalidParam represents a missing parameter CodeInvalidParam = "invalid_parameter" // CodeServerError represents a server error CodeServerError = "server_error" // CodeAuthorizationError represents an authorization error CodeAuthorizationError = "auth_error" // CodePutError represents a failure to put an object CodePutError = "put_error" )
var ( // ServerError describe a server error ServerError = NewSingleAPIErr(500, "", "server_error", "server error", nil) // BodyMalformedError describes an error about a malformed json body BodyMalformedError = NewSingleAPIErr(400, "", "invalid_body", "malformed json body", nil) )
Functions ¶
func EasyHandle ¶
func EasyHandle(method string, handler func(w http.ResponseWriter, r *http.Request) (interface{}, int)) func(http.ResponseWriter, *http.Request)
EasyHandle takes a custom handle that returns any value type and a status code. An error response value whose message is a JSON string is considered to be a decoded common.APIError and will be encoded back to APIError and returned as JSON. The status code provided in APIError is used as the response status code. Other errors are returned as text. None errors are coerced and returned as JSON.
func GetKeyByValue ¶
GetKeyByValue gets a key by its value. The first key with a matching value is returned. If value is not found, def is returned
func MultiObjectResp ¶
MultiObjectResp creates standard response format for multiple objects
func NewAPIError ¶
NewAPIError creates an APIError that is encoded to JSON and returned as a standard error.
func NewMultiAPIErr ¶
NewMultiAPIErr returns a response with multiple errors
func NewSingleAPIErr ¶
NewSingleAPIErr returns a response with a single error
func SingleObjectResp ¶
SingleObjectResp creates standard response format for only a single object
func UnMapFields ¶
UnMapFields takes a mapping, an object or slice of objects that have mapped fields and produces a new object or slice of objects where the mapped, custom fields are converted to the original columns
Types ¶
type Error ¶
type Error struct { Status string `json:"status,omitempty" structs:"status,omitempty" mapstructure:"status,omitempty"` Code string `json:"code,omitempty" structs:"code,omitempty" mapstructure:"code,omitempty"` Field string `json:"field,omitempty" structs:"field,omitempty" mapstructure:"field,omitempty"` Message string `json:"message,omitempty" structs:"message,omitempty" mapstructure:"message,omitempty"` Links map[string]string `json:"links,omitempty" structs:"links,omitempty" mapstructure:"links,omitempty"` }
Error defines a single error