Documentation
¶
Index ¶
- Constants
- Variables
- func CopyFields(from interface{}, to interface{}) error
- func GetFieldValueByName(instance interface{}, fieldName string) (interface{}, error)
- func IsCapitalized(str string) bool
- func RespondError(w http.ResponseWriter, err error)
- func RespondOk(w http.ResponseWriter, code int, data interface{})
- func SetFieldValueByName(instance interface{}, fieldName string, value interface{}) error
- func StructToMap(instance interface{}) map[string]interface{}
- func ValidateRequired(instance interface{}) error
- func ZuluTimeNow() string
- type APIError
- type ErrResp
Constants ¶
View Source
const ( ContentType = "application/json" Charset = "utf-8" )
View Source
const ZULU_FORM = "2006-01-02T15:04:05Z"
Variables ¶
View Source
var APIErrBadRequest = func(msg string) *APIError { msg = fmt.Sprintf("Poorly formatted JSON. %v", msg) return &APIError{msg, 400, "BAD REQUEST"} }
View Source
var APIErrConflict = func(resource string, field string, value string) *APIError { msg := fmt.Sprintf("%v object with %v: %v already exists", resource, field, value) return &APIError{msg, 409, "CONFLICT"} }
View Source
var APIErrDatabase = func(msg string) *APIError { msg = fmt.Sprintf("Database Error: %v", msg) return &APIError{msg, 500, "INTERNAL SERVER ERROR"} }
View Source
var APIErrEmptyRequiredField = func(resource string, msg string) *APIError { return &APIError{fmt.Sprintf("%v object contains empty fields. %v", resource, msg), 422, "UNPROCESSABLE ENTITY"} }
View Source
var APIErrInvalidFieldContent = func(field string, reason string) *APIError { msg := fmt.Sprintf("Field: %v contains invalid data. %v", field, reason) return &APIError{msg, 422, "UNPROCESSABLE ENTITY"} }
View Source
var APIErrNotFound = func(resource string) *APIError { msg := fmt.Sprintf("%v was not found", resource) return &APIError{msg, 404, "NOT FOUND"} }
View Source
return &APIError{msg, 401, "UNAUTHORIZED"} }
View Source
var APIErrUnsupportedContent = func(place, content string, supported string) *APIError { msg := fmt.Sprintf("%v: %v is not yet supported.%v", place, content, supported) return &APIError{msg, 422, "UNPROCESSABLE ENTITY"} }
View Source
var APIErrUnsupportedContentNonVerbose = func(place, content string) *APIError { msg := fmt.Sprintf("%v: %v is not yet supported", place, content) return &APIError{msg, 422, "UNPROCESSABLE ENTITY"} }
View Source
var APIGenericInternalError = func(msg string) error { return &APIError{"Internal Error: " + msg, 500, "INTERNAL SERVER ERROR"} }
View Source
var GenericEmptyRequiredField = func(fieldName string) error { return errors.New(fmt.Sprintf("empty value for field: %v", fieldName)) }
View Source
var StructGenericEmptyRequiredField = func(strct string, reason string) error { return errors.New(fmt.Sprintf("%v object contains empty fields. %v", strct, reason)) }
also contains struct information
Functions ¶
func CopyFields ¶
func CopyFields(from interface{}, to interface{}) error
CopyFields finds same named field between two structs and copies the values from one to an other
func GetFieldValueByName ¶
GetFieldValueByName retrieves the value of a specified field from the provided instance
func IsCapitalized ¶
IsCapitalized returns whether or not not a string is capitalized
func RespondError ¶
func RespondError(w http.ResponseWriter, err error)
func RespondOk ¶
func RespondOk(w http.ResponseWriter, code int, data interface{})
func SetFieldValueByName ¶
SetFieldValueByName assigns a value to the specified field of the given interface
func StructToMap ¶
func StructToMap(instance interface{}) map[string]interface{}
StructToMap converts a non nil struct to a map of map[string]interface{}
func ValidateRequired ¶
func ValidateRequired(instance interface{}) error
ValidateRequired accepts an instance of any type and checks whether or not all fields are filled
func ZuluTimeNow ¶
func ZuluTimeNow() string
ZuluTimeNow returns the current UTC time in zulu format
Types ¶
Click to show internal directories.
Click to hide internal directories.