dynamic

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2020 License: MIT, MIT Imports: 8 Imported by: 32

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Function added in v0.3.0

func Function(ctx context.Context, vm *otto.Otto, fn interface{}) interface{}

Function wraps a function for execution in Javascript. It returns an object suitable for calling from a Javascript interpreter.

Function can take either a Go function, or a string that evaluates to a Javascript function.

If fn returns an error as its last return value, then Function will convert that error into a Javscript exception, if the error is non-nil.

If fn takes a context as its first argument, then Function will remove that argument from the returned Javascript function and implicitly inject the provided context.

Function will panic if called with an fn that does not have a reflect type of 'Func'.

A function like GetEvents(context.Context) ([]*corev2.Event, error) will get translated into something like GetEvents() []*corev2.Event.

The result will be a raw Go object.

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.

func SynthesizeMethods added in v0.3.0

func SynthesizeMethods(v interface{}) map[string]interface{}

SynthesizeMethods returns a map of method names to methods from v.

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