dynamic

package
v0.0.0-...-7ae29b8 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2023 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Logger hclog.Logger
View Source
var WellKnownTypeFns []*argmapper.Func

Functions

func BlindMap

func BlindMap(
	value interface{},
	mappers []*argmapper.Func,
	args ...argmapper.Arg,
) (interface{}, error)

This converts a value to another value using the provided mappers without any required type information. It is similar to the UnknownMap function but the expected type is not required. Due to this missing information, however, this function will be slower as it iterates the entire mapper list provided and attempts to call any function who's input signature includes a matching type for the given value.

func CallFunc

func CallFunc(
	f interface{},
	expectedType interface{},
	mappers []*argmapper.Func,
	args ...argmapper.Arg,
) (interface{}, error)

Calls the function provided and converts the result to an expected type. If no type conversion is required, a `false` value for the expectedType will return the raw interface return value.

func DecodeAny

func DecodeAny(
	input *anypb.Any,
) (t reflect.Type, r interface{}, err error)

Decode an Any proto and return the type and value

func EncodeAny

func EncodeAny(
	input proto.Message,
) (*anypb.Any, error)

Encode a proto message to Any

func Map

func Map(
	value,
	expectedType interface{},
	args ...argmapper.Arg,
) (interface{}, error)

Convert a value to an expected type. Converter functions should be included in the args list. It is important to note that the expectedType is a pointer to the desired type (including interfaces). For example, if an `int` is wanted, the expectedType would be `(*int)(nil)`.

func MapFromWellKnownProto

func MapFromWellKnownProto(
	input proto.Message,
) (interface{}, error)

Map a well known proto to value

func MapToWellKnownProto

func MapToWellKnownProto(
	input interface{},
) (proto.Message, error)

Map a well known value to proto

func UnknownMap

func UnknownMap(
	value,
	expectedType interface{},
	mappers []*argmapper.Func,
	args ...argmapper.Arg,
) (interface{}, error)

Convert a value to another value using provided mappers. This can be useful for converting a received value (like a proto) into an internal value. It works by searching the list of provided mappers for a functions that support an input argument of the type that matches (or satisfies) the given value. Extra args can be provided which are used when applying the mapping to convert the value. The expected type can be useful where a generic interface may be expected (like proto.Message).

Types

type SpecAndFunc

type SpecAndFunc struct {
	Func *argmapper.Func
	Spec *vagrant_plugin_sdk.FuncSpec
}

Wraps an argmapper Func with a FuncSpec definition to allow easy reuse with wrapped clients

Jump to

Keyboard shortcuts

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