Documentation ¶
Index ¶
- Constants
- Variables
- func CopyDefaults(a, b interface{})
- func CopyFrom(a, b interface{})
- func Equal(src interface{}, dst interface{}, excptFields ...string) bool
- func FieldName(name string) string
- func FlattenMap(a map[string]interface{}) map[string]interface{}
- func IsEmpty(v reflect.Value) bool
- func IsZero(src interface{}) bool
- func Lookup(i interface{}, path string) (reflect.Value, error)
- func Merge(dst interface{}, mp map[string]interface{}, opts ...Option) error
- func SetFieldByPath(src interface{}, dst interface{}, path string) error
- func StructFieldByName(src interface{}, tkey string) (interface{}, error)
- func StructFieldByPath(src interface{}, path string) (interface{}, error)
- func StructFieldByTag(src interface{}, tkey string, tval string) (interface{}, error)
- func StructFieldsMap(src interface{}) (map[string]interface{}, error)
- func StructURLValues(src interface{}, pref string, tags []string) (url.Values, error)
- func URLMap(query string) (map[string]interface{}, error)
- func Zero(src interface{}) (interface{}, error)
- func ZeroFieldByPath(src interface{}, path string) error
- type Option
- type Options
- type StructField
Constants ¶
const ( // SplitToken used to detect path components SplitToken = "." // IndexCloseChar used to detect index end IndexCloseChar = "]" // IndexOpenChar used to detect index start IndexOpenChar = "[" )
Variables ¶
var ( // ErrMalformedIndex returns when index key have invalid format ErrMalformedIndex = errors.New("malformed index key") // ErrInvalidIndexUsage returns when index key usage error ErrInvalidIndexUsage = errors.New("invalid index key usage") // ErrKeyNotFound returns when key not found ErrKeyNotFound = errors.New("unable to find the key") // ErrBadJSONPath returns when path have invalid syntax ErrBadJSONPath = errors.New("bad path: must start with $ and have more then 2 chars") )
var ( // ErrInvalidStruct happens when passed not struct and not struct pointer ErrInvalidStruct = errors.New("invalid struct specified") // ErrInvalidValue happens when passed invalid value for field ErrInvalidValue = errors.New("invalid value specified") // ErrNotFound happens when struct field not found ErrNotFound = errors.New("struct field not found") )
var ErrInvalidParam = errors.New("invalid url query param provided")
ErrInvalidParam specifies invalid url query params
Functions ¶
func CopyDefaults ¶
func CopyDefaults(a, b interface{})
CopyDefaults for a from b a and b should be pointers to the same kind of struct
func CopyFrom ¶
func CopyFrom(a, b interface{})
CopyFrom sets the public members of a from b a and b should be pointers to structs a can be a different type from b Only the Fields which have the same name and assignable type on a and b will be set.
func FlattenMap ¶
FlattenMap expand key.subkey to nested map
func IsZero ¶
func IsZero(src interface{}) bool
IsZero returns true if struct is zero (not have any defined values)
func Lookup ¶
Lookup performs a lookup into a value, using a path of keys. The key should match with a Field or a MapIndex. For slice you can use the syntax key[index] to access a specific index. If one key owns to a slice and an index is not specificied the rest of the path will be apllied to evaley value of the slice, and the value will be merged into a slice.
func SetFieldByPath ¶
SetFieldByPath set struct field by its path
func StructFieldByName ¶
StructFieldByName get struct field by its name
func StructFieldByPath ¶
StructFieldByPath get struct field by its path
func StructFieldByTag ¶
StructFieldByTag get struct field by tag key and its value
func StructFieldsMap ¶
StructFieldsMap returns struct map[string]interface{} or error
func StructURLValues ¶
StructURLValues get struct fields via url.Values
func ZeroFieldByPath ¶
ZeroFieldByPath clean struct field by its path
Types ¶
type Options ¶
type Options struct { // Tags specifies tags to lookup Tags []string // SliceAppend controls slice appending SliceAppend bool }
Options for merge
type StructField ¶
type StructField struct { Value reflect.Value Path string Field reflect.StructField }
StructField contains struct field path its value and field
func StructFields ¶
func StructFields(src interface{}) ([]StructField, error)
StructFields returns slice of struct fields