reflectutil

package
v0.0.0-...-d47e5ee Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToString

func BytesToString(data []byte) string

BytesToString converts the provided byte slice into a string. No copy is performed, which means that changing the data slice will also change the string, which will break any code that relies on the assumption that strings are read-only. Use with care.

func ConstantToFloat

func ConstantToFloat(constv constant.Value) reflect.Value

ConstantToFloat returns a float-like value from a constant. It will return a float64, *big.Rat, or *big.Float depending on whether the value fits in the types in that order without losing precision.

func ConstantToInt

func ConstantToInt(constv constant.Value) reflect.Value

ConstantToInt returns an int-like value from a constant. It will return an int, uint, or *big.Int depending on whether the value fits in the types in that order.

func DeepEqual

func DeepEqual(lhs, rhs interface{}, fn func(lhs, rhs reflect.Value) (bool, error)) error

func IsList

func IsList(typ reflect.Type) bool

func IsMap

func IsMap(typ reflect.Type) bool

func IsValueType

func IsValueType(t reflect.Type) bool

IsValueType returns true if the specified type can be represented as a single value.

func Len

func Len(v reflect.Value) int

Len returns the "length" of the specified value. If v is a map, slice, or array, it returns its length If v is a struct, it returns the number of fields For everything else, Len returns 1.

func Marshal

func Marshal(val reflect.Value, marshaler Marshaler, convention NamingConvention) error

func PopulateFromEnv

func PopulateFromEnv(to reflect.Value, automatic bool, names []string, lookup func(string) (string, bool)) (bool, error)

func Set

func Set(val reflect.Value, node *syntax.Node, convention encoding.NamingConvention, unmarshaler Unmarshaler, at ...interface{}) (outerr error)

func SetScalar

func SetScalar(to reflect.Value, value interface{}, nodetype syntax.NodeType) (bool, error)

func ToScalar

func ToScalar(val reflect.Value) reflect.Value

func Unmarshal

func Unmarshal(val reflect.Value, node *syntax.Node, convention encoding.NamingConvention, merge bool, unmarshaler Unmarshaler) error

func UnmarshalText

func UnmarshalText(to reflect.Value, value string) (bool, error)

Types

type FieldOpts

type FieldOpts struct {
	Name   string
	Help   []string
	Ignore bool
	Naming NamingConvention
	Inline bool
	Env    string
}

func ParseFieldOpts

func ParseFieldOpts(tag reflect.StructTag, marshaler interface{}, convention NamingConvention) (opts FieldOpts)

ParseFieldOpts parses the standard set of field options that boa supports.

type InfMarshaler

type InfMarshaler interface {
	MarshalInf(inf float64) error
}

type MapEntry

type MapEntry struct {
	Key     string
	Value   reflect.Value
	Options FieldOpts
}

func VisibleFieldsAsMapEntries

func VisibleFieldsAsMapEntries(val reflect.Value, convention encoding.NamingConvention, marshaler interface{}) []MapEntry

type Marshaler

type Marshaler interface {
	MarshalValue(v reflect.Value) (bool, error)
	MarshalList(v reflect.Value) (bool, error)
	MarshalListElem(l, v reflect.Value, i int) (bool, error)
	MarshalMap(v reflect.Value, kvs []MapEntry) (bool, error)
	MarshalMapKey(mv reflect.Value, kv MapEntry, i int) error
	MarshalMapValue(mv reflect.Value, kv MapEntry, i int) (bool, error)

	MarshalBool(v bool) error
	MarshalString(v string) error
	MarshalNumber(v constant.Value) error
}

type NaNMarshaler

type NaNMarshaler interface {
	MarshalNaN(nan float64) error
}

type NilMarshaler

type NilMarshaler interface {
	MarshalNil() error
}

type PostListElemMarshaler

type PostListElemMarshaler interface {
	MarshalListElemPost(l, v reflect.Value, i int) error
}

type PostListMarshaler

type PostListMarshaler interface {
	MarshalListPost(v reflect.Value) error
}

type PostMapMarshaler

type PostMapMarshaler interface {
	MarshalMapPost(v reflect.Value, kvs []MapEntry) error
}

type PostMapValueMarshaler

type PostMapValueMarshaler interface {
	MarshalMapValuePost(mv reflect.Value, kv MapEntry, i int) error
}

type Stringifier

type Stringifier interface {
	Stringify(v reflect.Value) (string, bool, error)
}

type StructField

type StructField struct {
	reflect.StructField
	Value   reflect.Value
	Options FieldOpts
}

func VisibleFields

func VisibleFields(val reflect.Value, convention encoding.NamingConvention, unmarshaler interface{}) ([]StructField, map[string]StructField)

type StructTagParser

type StructTagParser interface {
	ParseStructTag(tag reflect.StructTag) (FieldOpts, bool)
}

type Tag

type Tag struct {
	Key     string
	Value   string
	Options []string
}

func LookupTag

func LookupTag(tag reflect.StructTag, key string, options bool) (Tag, bool)

type UnmarshalFunc

type UnmarshalFunc func(val reflect.Value, node *syntax.Node) (bool, error)

type Unmarshaler

type Unmarshaler interface {
	UnmarshalValue(val reflect.Value, node *syntax.Node) (bool, error)
}

Jump to

Keyboard shortcuts

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