dynamic

package
v5.10.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2019 License: MIT, MIT, MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetField

func GetField(v interface{}, name string) (interface{}, error)

GetField gets a field from v according to its name. If GetField doesn't find a struct field with the corresponding name, then it will try to dynamically find the corresponding item in the 'Extended' field. GetField is case-sensitive, but extended attribute names will be converted to CamelCaps.

func SetField

func SetField(v interface{}, path string, value interface{}) error

SetField inserts a value into v at path.

For example, if the marshalled representation of v is {"foo": "bar", "baz": { "value": 5 }}, Then SetField(v, "baz.value", 10) will result in {"foo": "bar", "baz": { "value": 10 }}.

v's reflect.Kind must be reflect.Struct, or a non-nil error will be returned. If the path refers to a struct field, then v must be addressable, or an error will be returned.

func Synthesize

func Synthesize(v interface{}) interface{}

Synthesize recursively turns structs into map[string]interface{} values. It works on most datatypes. Synthesize panics if it is called on channels.

Synthesize will use the json tag from struct fields to name map keys, if the json tag is present.

Types

type SynthesizeExtras

type SynthesizeExtras interface {
	// SynthesizeExtras returns a map of extra values to include when passing
	// to Synthesize().
	SynthesizeExtras() map[string]interface{}
}

SynthesizeExtras is a type that wants to pass extra values to the Synthesize function. The key-value pairs will be included as-is without inspection by the Synthesize function. This is useful for populated synthesized values with functions or computed values.

Jump to

Keyboard shortcuts

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