apivalues

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2022 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrOutOfRange        = errors.New("out of range")
	ErrIncompatibleValue = errors.New("incompatible value")
)
View Source
var (
	// Ignore current value's children.
	ErrSkip = errors.New("skip")

	// Abort scanning of current fields of parent and continue to parent sibling, if exists.
	ErrUp = errors.New("up")
)
View Source
var ErrNoConversion = errors.New("no convertion")
View Source
var ErrUnknownType = errors.New("(proto) unknown type")

Functions

func GetConcretValue

func GetConcretValue[T any](v *Value) *T

func Length

func Length(v *Value) (int, error)

func MustStringValueMapFromProto

func MustStringValueMapFromProto(m map[string]*pbvalues.Value) map[string]*Value

func SetCallIssuer

func SetCallIssuer(v *Value, issuer string) error

This mutates v.

func StringValueMapFromProto

func StringValueMapFromProto(m map[string]*pbvalues.Value) (map[string]*Value, error)

func StringValueMapToProto

func StringValueMapToProto(m map[string]*Value) map[string]*pbvalues.Value

func Take

func Take(v *Value, idx, count int) (*Value, []*Value, error)

func Unwrap

func Unwrap(v value, fopts ...func(*unwrapOpts)) interface{}

func UnwrapInto

func UnwrapInto(dst interface{}, v value, fopts ...func(*unwrapOpts)) error

func UnwrapValuesMap

func UnwrapValuesMap(m map[string]*Value, fopts ...func(*unwrapOpts)) map[string]interface{}

func ValuesListToProto

func ValuesListToProto(vs []*Value) []*pbvalues.Value

func Walk

func Walk(v *Value, f func(curr, parent *Value, role Role) error) error

NOTE: f can mutate the values it's given if it chooses to.

func WithDictSorter

func WithDictSorter(s func([]*DictItem)) func(*wrapOpts)

func WithListSorter

func WithListSorter(s func([]*Value)) func(*wrapOpts)

func WithStructFieldNameConverter

func WithStructFieldNameConverter(f func(string) string) func(*wrapOpts)

func WithUnwrapJSONSafe

func WithUnwrapJSONSafe() func(*unwrapOpts)

func WithWrapTranslate

func WithWrapTranslate(t func(interface{}) (interface{}, error)) func(*wrapOpts)

func WrapIntoValuesMap

func WrapIntoValuesMap(dst map[string]*Value, v interface{}, wopts ...func(*wrapOpts)) error

func WrapValuesMap

func WrapValuesMap(dst map[string]*Value, m map[string]interface{}, wopts ...func(*wrapOpts)) error

Types

type BooleanValue

type BooleanValue bool

func (*BooleanValue) ConvertFrom

func (b *BooleanValue) ConvertFrom(v value) error

func (BooleanValue) String

func (b BooleanValue) String() string

type BytesValue

type BytesValue []byte

func (*BytesValue) ConvertFrom

func (b *BytesValue) ConvertFrom(v value) error

func (BytesValue) String

func (b BytesValue) String() string

type CallValue

type CallValue struct {
	Name   string          `json:"name"`
	ID     string          `json:"id"`
	Issuer string          `json:"issuer"`
	Flags  map[string]bool `json:"flags"` // set only by ak. not by user.
}

func GetCallValue

func GetCallValue(v *Value) *CallValue

func (CallValue) String

func (c CallValue) String() string

type DictItem

type DictItem struct{ K, V *Value }

type DictValue

type DictValue []*DictItem

func GetDictValue

func GetDictValue(v *Value) *DictValue

func (*DictValue) ConvertFrom

func (d *DictValue) ConvertFrom(v value) error

func (DictValue) GetKey

func (d DictValue) GetKey(k *Value) *DictItem

func (DictValue) String

func (d DictValue) String() string

func (DictValue) ToStringValuesMap

func (d DictValue) ToStringValuesMap(dst map[string]*Value)

type DurationValue

type DurationValue time.Duration

func (*DurationValue) ConvertFrom

func (d *DurationValue) ConvertFrom(v value) error

func (DurationValue) String

func (d DurationValue) String() string

func (DurationValue) UnwrapInto

func (d DurationValue) UnwrapInto(dst interface{}) (bool, error)

type FloatValue

type FloatValue float32

func (*FloatValue) ConvertFrom

func (f *FloatValue) ConvertFrom(v value) error

func (FloatValue) IsIntegral

func (f FloatValue) IsIntegral() bool

func (FloatValue) String

func (f FloatValue) String() string

func (FloatValue) UnwrapInto

func (f FloatValue) UnwrapInto(dst interface{}) (bool, error)

type FunctionSignature

type FunctionSignature struct {
	Name          string   `json:"name"`
	Doc           string   `json:"doc"`
	NumArgs       uint32   `json:"num_args"`
	NumKWOnlyArgs uint32   `json:"num_kwonly_args"`
	ArgsNames     []string `json:"args_names"`
	HasKWArgs     bool     `json:"has_kwargs"`
	HasVarargs    bool     `json:"has_varargs"`
}

type FunctionValue

type FunctionValue struct {
	Lang   string `json:"lang"`
	FuncID string `json:"func_id"`
	Scope  string `json:"scope"`

	Signature *FunctionSignature `json:"signature"` // optional
}

func GetFunctionValue

func GetFunctionValue(v *Value) *FunctionValue

func ParseFunctionValueString

func ParseFunctionValueString(s string) (*FunctionValue, error)

func (FunctionValue) String

func (c FunctionValue) String() string

type IntegerValue

type IntegerValue int64

func (*IntegerValue) ConvertFrom

func (i *IntegerValue) ConvertFrom(v value) error

func (IntegerValue) String

func (i IntegerValue) String() string

func (IntegerValue) UnwrapInto

func (i IntegerValue) UnwrapInto(dst interface{}) (bool, error)

type ListValue

type ListValue []*Value

func GetListValue

func GetListValue(v *Value) ListValue

func (*ListValue) ConvertFrom

func (l *ListValue) ConvertFrom(v value) error

func (ListValue) String

func (l ListValue) String() string

type ModuleValue

type ModuleValue struct {
	Name    string            `json:"name"`
	Members map[string]*Value `json:"members"`
}

func GetModuleValue

func GetModuleValue(v *Value) *ModuleValue

func (ModuleValue) String

func (c ModuleValue) String() string

type NoneValue

type NoneValue struct{}

func (NoneValue) ConvertFrom

func (NoneValue) ConvertFrom(v value) error

func (NoneValue) String

func (NoneValue) String() string

type Role

type Role string
const (
	RoleNone             Role = ""
	RoleListItem         Role = "list_item"
	RoleSetItem          Role = "set_item"
	RoleStructCtor       Role = "struct_ctor"
	RoleDictKey          Role = "dict_key"
	RoleDictValue        Role = "dict_value"
	RoleStructFieldValue Role = "struct_field_value"
	RoleModuleMember     Role = "module_member"
)

type SetValue

type SetValue []*Value

func (*SetValue) ConvertFrom

func (s *SetValue) ConvertFrom(v value) error

func (SetValue) String

func (s SetValue) String() string

type StringValue

type StringValue string

func (*StringValue) ConvertFrom

func (s *StringValue) ConvertFrom(v value) error

func (StringValue) String

func (s StringValue) String() string

func (StringValue) UnwrapInto

func (s StringValue) UnwrapInto(dst interface{}) (bool, error)

type StructValue

type StructValue struct {
	Ctor   *Value            `json:"ctor"`
	Fields map[string]*Value `json:"fields"`
}

func GetStructValue

func GetStructValue(v *Value) *StructValue

func (StructValue) String

func (s StructValue) String() string

type SymbolValue

type SymbolValue string

func (*SymbolValue) ConvertFrom

func (s *SymbolValue) ConvertFrom(v value) error

func (SymbolValue) String

func (s SymbolValue) String() string

type TimeValue

type TimeValue time.Time

func (*TimeValue) ConvetFrom

func (t *TimeValue) ConvetFrom(v value) error

func (TimeValue) String

func (t TimeValue) String() string

func (TimeValue) UnwrapInto

func (t TimeValue) UnwrapInto(dst interface{}) (bool, error)

type Value

type Value struct {
	// contains filtered or unexported fields
}

func Add

func Add(a, b *Value) (*Value, error)

func Boolean

func Boolean(b bool) *Value

func Bytes

func Bytes(bs []byte) *Value

func Dict

func Dict(items ...*DictItem) *Value

func DictFromMap

func DictFromMap(m map[string]*Value) *Value

func Div

func Div(a, b *Value) (*Value, error)

func Duration

func Duration(d time.Duration) *Value

func Float

func Float(f float32) *Value

func Foldr

func Foldr(f func(a, b *Value) (*Value, error), v0 *Value, vs []*Value) (*Value, error)

func GetKey

func GetKey(v, k *Value) (*Value, error)

func Inc

func Inc(v *Value, amount int64) (*Value, error)

func Index

func Index(v *Value, idx int) (*Value, error)

func Insert

func Insert(v *Value, idx int, vv *Value) (*Value, error)

func Integer

func Integer(i int64) *Value

func Keys

func Keys(v *Value) (*Value, error)

func List

func List(items ...*Value) *Value

func Module

func Module(name string, members map[string]*Value) *Value

func Mul

func Mul(a, b *Value) (*Value, error)

func MustNewValue

func MustNewValue(v value) *Value

func MustValueFromProto

func MustValueFromProto(pb *pbvalues.Value) *Value

func MustValuesListFromProto

func MustValuesListFromProto(pbs []*pbvalues.Value) []*Value

func MustWrap

func MustWrap(v interface{}, wopts ...func(*wrapOpts)) *Value

func NewValue

func NewValue(v value) (*Value, error)

func Set

func Set(vs ...*Value) *Value

func SetKey

func SetKey(v, kv, vv *Value) (*Value, error)

func String

func String(s string) *Value

func StringList

func StringList(items ...string) *Value

func Struct

func Struct(ctor *Value, fields map[string]*Value) *Value

func Symbol

func Symbol(s string) *Value

func Time

func Time(t time.Time) *Value

func ValueFromProto

func ValueFromProto(pb *pbvalues.Value) (*Value, error)

func ValuesListFromProto

func ValuesListFromProto(pbs []*pbvalues.Value) ([]*Value, error)

func Wrap

func Wrap(v interface{}, wopts ...func(*wrapOpts)) (*Value, error)

func (*Value) Clone

func (v *Value) Clone() *Value

func (*Value) Equal

func (v *Value) Equal(o *Value) bool

func (*Value) Get

func (v *Value) Get() value

func (*Value) IsEphemeral

func (v *Value) IsEphemeral() bool

func (*Value) MarshalJSON

func (v *Value) MarshalJSON() ([]byte, error)

func (*Value) PB

func (v *Value) PB() *pbvalues.Value

func (*Value) String

func (v *Value) String() string

func (*Value) UnmarshalJSON

func (v *Value) UnmarshalJSON(bs []byte) error

func (*Value) Unwrap

func (v *Value) Unwrap(fopts ...func(*unwrapOpts)) interface{}

type ValuePB

type ValuePB = pbvalues.Value

Jump to

Keyboard shortcuts

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