Documentation ¶
Index ¶
- Constants
- Variables
- func ConcatJSON(blobs ...[]byte) []byte
- func ContainsStringsCI(coll []string, item string) bool
- func ConvertBool(str string) (bool, error)
- func ConvertFloat32(str string) (float32, error)
- func ConvertFloat64(str string) (float64, error)
- func ConvertInt16(str string) (int16, error)
- func ConvertInt32(str string) (int32, error)
- func ConvertInt64(str string) (int64, error)
- func ConvertInt8(str string) (int8, error)
- func ConvertUint16(str string) (uint16, error)
- func ConvertUint32(str string) (uint32, error)
- func ConvertUint64(str string) (uint64, error)
- func ConvertUint8(str string) (uint8, error)
- func DynamicJSONToStruct(data interface{}, target interface{}) error
- func FindInGoSearchPath(pkg string) string
- func FindInSearchPath(searchPath, pkg string) string
- func FormatBool(value bool) string
- func FormatFloat32(value float32) string
- func FormatFloat64(value float64) string
- func FormatInt16(value int16) string
- func FormatInt32(value int32) string
- func FormatInt64(value int64) string
- func FormatInt8(value int8) string
- func FormatUint16(value uint16) string
- func FormatUint32(value uint32) string
- func FormatUint64(value uint64) string
- func FormatUint8(value uint8) string
- func FromDynamicJSON(data, target interface{}) error
- func FullGoSearchPath() string
- func IsFloat64AJSONInteger(f float64) bool
- func IsZero(data interface{}) bool
- func JSONDoc(path string) (json.RawMessage, error)
- func JoinByFormat(data []string, format string) []string
- func LoadFromFileOrHTTP(path string) ([]byte, error)
- func LoadStrategy(path string, local, remote func(string) ([]byte, error)) func(string) ([]byte, error)
- func SplitByFormat(data, format string) []string
- func ToCommandName(name string) string
- func ToDynamicJSON(data interface{}) interface{}
- func ToFileName(name string) string
- func ToGoName(name string) string
- func ToHumanNameLower(name string) string
- func ToJSONName(name string) string
- func YAMLData(path string) (interface{}, error)
- func YAMLDoc(path string) (json.RawMessage, error)
- func YAMLToJSON(data interface{}) (json.RawMessage, error)
- type NameProvider
- func (n *NameProvider) GetGoName(subject interface{}, name string) (string, bool)
- func (n *NameProvider) GetGoNameForType(tpe reflect.Type, name string) (string, bool)
- func (n *NameProvider) GetJSONName(subject interface{}, name string) (string, bool)
- func (n *NameProvider) GetJSONNameForType(tpe reflect.Type, name string) (string, bool)
- func (n *NameProvider) GetJSONNames(subject interface{}) []string
Constants ¶
const (
// GOPATHKey represents the env key for gopath
GOPATHKey = "GOPATH"
)
Variables ¶
var DefaultJSONNameProvider = NewNameProvider()
DefaultJSONNameProvider the default cache for types
Functions ¶
func ConcatJSON ¶
ConcatJSON concatenates multiple json objects efficiently
func ContainsStringsCI ¶
ContainsStringsCI searches a slice of strings for a case-insensitive match
func ConvertBool ¶
ConvertBool turn a string into a boolean
func ConvertFloat32 ¶
ConvertFloat32 turn a string into a float32
func ConvertFloat64 ¶
ConvertFloat64 turn a string into a float64
func ConvertInt16 ¶
ConvertInt16 turn a string into a int16
func ConvertInt32 ¶
ConvertInt32 turn a string into a int32
func ConvertInt64 ¶
ConvertInt64 turn a string into a int64
func ConvertInt8 ¶
ConvertInt8 turn a string into int8 boolean
func ConvertUint16 ¶
ConvertUint16 turn a string into a uint16
func ConvertUint32 ¶
ConvertUint32 turn a string into a uint32
func ConvertUint64 ¶
ConvertUint64 turn a string into a uint64
func ConvertUint8 ¶
ConvertUint8 turn a string into a uint8
func DynamicJSONToStruct ¶
func DynamicJSONToStruct(data interface{}, target interface{}) error
DynamicJSONToStruct converts an untyped json structure into a struct
func FindInGoSearchPath ¶
FindInGoSearchPath finds a package in the $GOPATH:$GOROOT
func FindInSearchPath ¶
FindInSearchPath finds a package in a provided lists of paths
func FormatFloat32 ¶
FormatFloat32 turns a float32 into a string
func FormatFloat64 ¶
FormatFloat64 turns a float64 into a string
func FormatUint16 ¶
FormatUint16 turns an uint16 into a string
func FormatUint32 ¶
FormatUint32 turns an uint32 into a string
func FormatUint64 ¶
FormatUint64 turns an uint64 into a string
func FromDynamicJSON ¶
func FromDynamicJSON(data, target interface{}) error
FromDynamicJSON turns an object into a properly JSON typed structure
func FullGoSearchPath ¶
func FullGoSearchPath() string
FullGoSearchPath gets the search paths for finding packages
func IsFloat64AJSONInteger ¶
IsFloat64AJSONInteger allow for integers [-2^53, 2^53-1] inclusive
func IsZero ¶
func IsZero(data interface{}) bool
IsZero returns true when the value passed into the function is a zero value. This allows for safer checking of interface values.
func JSONDoc ¶
func JSONDoc(path string) (json.RawMessage, error)
JSONDoc loads a json document from either a file or a remote url
func JoinByFormat ¶
JoinByFormat joins a string array by a known format:
ssv: space separated value tsv: tab separated value pipes: pipe (|) separated value csv: comma separated value (default)
func LoadFromFileOrHTTP ¶
LoadFromFileOrHTTP loads the bytes from a file or a remote http server based on the path passed in
func LoadStrategy ¶
func LoadStrategy(path string, local, remote func(string) ([]byte, error)) func(string) ([]byte, error)
LoadStrategy returns a loader function for a given path or uri
func SplitByFormat ¶
SplitByFormat splits a string by a known format:
ssv: space separated value tsv: tab separated value pipes: pipe (|) separated value csv: comma separated value (default)
func ToCommandName ¶
ToCommandName lowercases and underscores a go type name
func ToDynamicJSON ¶
func ToDynamicJSON(data interface{}) interface{}
ToDynamicJSON turns an object into a properly JSON typed structure
func ToFileName ¶
ToFileName lowercases and underscores a go type name
func ToGoName ¶
ToGoName translates a swagger name which can be underscored or camel cased to a name that golint likes
func ToHumanNameLower ¶
ToHumanNameLower represents a code name as a human series of words
func ToJSONName ¶
ToJSONName camelcases a name which can be underscored or pascal cased
func YAMLDoc ¶
func YAMLDoc(path string) (json.RawMessage, error)
YAMLDoc loads a yaml document from either http or a file and converts it to json
func YAMLToJSON ¶
func YAMLToJSON(data interface{}) (json.RawMessage, error)
YAMLToJSON converts YAML unmarshaled data into json compatible data
Types ¶
type NameProvider ¶
type NameProvider struct {
// contains filtered or unexported fields
}
NameProvider represents an object capabale of translating from go property names to json property names This type is thread-safe.
func NewNameProvider ¶
func NewNameProvider() *NameProvider
NewNameProvider creates a new name provider
func (*NameProvider) GetGoName ¶
func (n *NameProvider) GetGoName(subject interface{}, name string) (string, bool)
GetGoName gets the go name for a json property name
func (*NameProvider) GetGoNameForType ¶
GetGoNameForType gets the go name for a given type for a json property name
func (*NameProvider) GetJSONName ¶
func (n *NameProvider) GetJSONName(subject interface{}, name string) (string, bool)
GetJSONName gets the json name for a go property name
func (*NameProvider) GetJSONNameForType ¶
GetJSONNameForType gets the json name for a go property name on a given type
func (*NameProvider) GetJSONNames ¶
func (n *NameProvider) GetJSONNames(subject interface{}) []string
GetJSONNames gets all the json property names for a type