reflect

package
v3.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SplitToken     = "."
	IndexCloseChar = "]"
	IndexOpenChar  = "["
)

Variables

View Source
var (
	ErrMalformedIndex    = errors.New("Malformed index key")
	ErrInvalidIndexUsage = errors.New("Invalid index key usage")
	ErrKeyNotFound       = errors.New("Unable to find the key")
	ErrBadJSONPath       = errors.New("Bad path: must start with $ and have more then 2 chars")
)
View Source
var (
	ErrInvalidStruct = errors.New("invalid struct specified")
	ErrInvalidValue  = errors.New("invalid value specified")
	ErrNotFound      = errors.New("struct field not found")
)
View Source
var ErrInvalidParam = errors.New("invalid url query param provided")

ErrInvalidParam specifies invalid url query params

Functions

func CopyDefaults added in v3.1.4

func CopyDefaults(a, b interface{})

CopyDefaults for a from b a and b should be pointers to the same kind of struct

func CopyFrom added in v3.1.4

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 FieldName added in v3.3.13

func FieldName(name string) string

func FlattenMap added in v3.2.8

func FlattenMap(a map[string]interface{}) map[string]interface{}

FlattenMap expand key.subkey to nested map

func IsEmpty

func IsEmpty(v reflect.Value) bool

IsEmpty returns true if value empty

func IsZero added in v3.2.24

func IsZero(src interface{}) bool

IsZero returns true if struct is zero (not have any defined values)

func Lookup added in v3.2.12

func Lookup(i interface{}, path string) (reflect.Value, error)

func Merge added in v3.3.13

func Merge(dst interface{}, mp map[string]interface{}, opts ...Option) error

func StructFieldByName added in v3.3.18

func StructFieldByName(src interface{}, tkey string) (interface{}, error)

func StructFieldByPath added in v3.5.0

func StructFieldByPath(src interface{}, path string) (interface{}, error)

func StructFieldByTag added in v3.3.18

func StructFieldByTag(src interface{}, tkey string, tval string) (interface{}, error)

func StructFieldsMap added in v3.5.0

func StructFieldsMap(src interface{}) (map[string]interface{}, error)

StructFieldsMap returns map[string]interface{} or error

func StructURLValues added in v3.3.10

func StructURLValues(src interface{}, pref string, tags []string) (url.Values, error)

func URLMap added in v3.2.8

func URLMap(query string) (map[string]interface{}, error)

URLMap returns map of url query params

func Zero

func Zero(src interface{}) (interface{}, error)

Zero creates new zero interface

Types

type Option added in v3.3.13

type Option func(*Options)

func SliceAppend added in v3.3.13

func SliceAppend(b bool) Option

func Tags added in v3.3.13

func Tags(t []string) Option

type Options added in v3.3.13

type Options struct {
	Tags        []string
	SliceAppend bool
}

type StructField added in v3.3.22

type StructField struct {
	Field reflect.StructField
	Value reflect.Value
	Path  string
}

func StructFields added in v3.1.4

func StructFields(src interface{}) ([]StructField, error)

StructFields returns slice of struct fields

Jump to

Keyboard shortcuts

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