lookup

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2020 License: Apache-2.0 Imports: 4 Imported by: 4

Documentation

Overview

Small library on top of reflect for make lookups to Structs or Maps. Using a very simple DSL you can access to any property, key or value of any value of Go.

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")
)

Functions

func FieldByTagName

func FieldByTagName(ty reflect.Type, key string) (*reflect.StructField, bool)

func Lookup

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

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 LookupString

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

LookupString performs a lookup into a value, using a string. Same as `Loookup` but using a string with the keys separated by `.`

func ValueByTagName

func ValueByTagName(v reflect.Value, key string) (reflect.Value, bool)

Types

This section is empty.

Jump to

Keyboard shortcuts

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