Documentation
¶
Index ¶
- func FieldTag(obj interface{}, lookup string, tag string) string
- func GetFromOffset(input string, offset int) (string, error)
- func GetResourceID(data interface{}) (string, error)
- func GetTags(obj reflect.StructField) []string
- func MapStringToInterface(vars map[string]string) map[string]interface{}
- func MarshalResponse(s JSONAPISchema) map[string]interface{}
- func NiceError(ctx *gin.Context, err error, code int)
- func ReturnTags(obj interface{}, lookup string) map[string]interface{}
- func ValidateAndMap(in io.Reader, schemaPath string, schema types.Schema) (map[string]interface{}, error)
- func ValidateInput(source []byte, schema string) error
- type APIError
- type JSONAPISchema
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetFromOffset ¶
GetFromOffset generates a human-readable line/character error from a JSON error's offset
func GetResourceID ¶
GetResourceID tries to extract the ID from data given
func GetTags ¶
func GetTags(obj reflect.StructField) []string
GetTags takes a reflect.StructField object and returns a slice of the associated tags
func MapStringToInterface ¶
MapStringToInterface converts map[string]string to a map[string]interface{}
func MarshalResponse ¶
func MarshalResponse(s JSONAPISchema) map[string]interface{}
MarshalResponse takes an object that implements the JSONAPISchema interface and marshals it to a map[string]interface{} Sub-structs will be placed automatically under their parent (meta/attr) so there is no need to have that tag on any sub-struct
func NiceError ¶
NiceError factors away the erroring of a function into a clean single-line function call
func ReturnTags ¶
ReturnTags takes an interface and a string to look up the tag for. If the first argument passed is a struct, then it starts looking for the tag given by the second argument & will return any it finds in map form
func ValidateAndMap ¶
func ValidateAndMap(in io.Reader, schemaPath string, schema types.Schema) (map[string]interface{}, error)
ValidateAndMap takes an io reader (most like io.ReadCloser from the request), reads in the data, and then validates it against the JSONSchema provided. Then it converts it into the provided schema via the interface (it's always a struct as we use it) to apply the JSON stuff we want and then returns a map
func ValidateInput ¶
ValidateInput valids the data provided against the provided JSON schema Will only return an error if there's a problem with the data
Types ¶
type APIError ¶
type APIError struct {
Data map[string]interface{}
}
APIError is an alias for map[string]string to make cleaner code
type JSONAPISchema ¶
JSONAPISchema is an interface used for generating the proper JSON API response packet