util

package
v0.0.0-...-2e5e463 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2018 License: MIT Imports: 13 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FieldTag

func FieldTag(obj interface{}, lookup string, tag string) string

FieldTag looks up a single field in the provided object and returns the tag for it

func GetFromOffset

func GetFromOffset(input string, offset int) (string, error)

GetFromOffset generates a human-readable line/character error from a JSON error's offset

func GetResourceID

func GetResourceID(data interface{}) (string, error)

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

func MapStringToInterface(vars map[string]string) map[string]interface{}

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

func NiceError(ctx *gin.Context, err error, code int)

NiceError factors away the erroring of a function into a clean single-line function call

func ReturnTags

func ReturnTags(obj interface{}, lookup string) map[string]interface{}

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

func ValidateInput(source []byte, schema string) error

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

func (APIError) Error

func (e APIError) Error() string

Error allows APIError to be returned as an error object

type JSONAPISchema

type JSONAPISchema interface {
	GetAPITag(lookup string) string
}

JSONAPISchema is an interface used for generating the proper JSON API response packet

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL