value

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2023 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CtxValue

func CtxValue[T any](ctx context.Context) *T

CtxValue returns the Value stored in the context.Context, or nil if not stored.

func CtxWith

func CtxWith[T any](parent context.Context, v *T) context.Context

CtxWith returns a new context.Context with the Value stored in it.

func DefaultLogHandler

func DefaultLogHandler(log *Log)

func DoIfCtxValueValid

func DoIfCtxValueValid[T any, TI isValid[T]](ctx context.Context, fn func(v *T))

DoIfCtxValueValid calls the function fn with the Value stored in the context.Context. If the Value is not valid, the function fn will not be called.

Types

type Kind

type Kind int
const (
	// Invalid is used for a Value without data.
	Invalid Kind = iota
	Vlist        // Vlist is a []Value Value.
	Vmap         // Vmap is a map[string]Value Value.
	Vbool
	Vint64
	Vfloat64
	Vstring
	Vtime   // Vtime is a time.Time Value.
	VbigInt // VbigInt is a *big.Int Value.
)

func (Kind) String

func (k Kind) String() string

String returns the name of k.

type List

type List []Value

List represents a list of Values.

func (*List) ToValue

func (v *List) ToValue() Value

ToValue returns then List as a Value.

type Log

type Log struct {
	Value
	Err error
}

Log repsents a log object base on Value.

func (*Log) Valid

func (l *Log) Valid() bool

type Map

type Map map[string]Value

Map represents a map of string to Value.

func (Map) Has

func (v Map) Has(key string) bool

Has returns true if the given key exists in the Set.

func (Map) Keys

func (v Map) Keys() []string

Keys returns a list of sorted keys in the Set.

func (*Map) ToValue

func (v *Map) ToValue() Value

ToValue returns the Map as a Value.

func (Map) ToValues

func (v Map) ToValues() List

ToValues returns a list of Values in the Set, which are sorted by keys.

type Value

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

Value represents a value of a set of types.

func BigInt

func BigInt(v *big.Int) Value

BigInt creates a *big.Int Value.

func Bool

func Bool(v bool) Value

Bool creates a bool Value.

func Float64

func Float64(v float64) Value

Float64 creates a float64 Value.

func Int

func Int(v int) Value

Int creates a int64 Value.

func Int64

func Int64(v int64) Value

Int64 creates a int64 Value.

func NewList

func NewList(cap int) Value

NewList creates a new List Value with given capacity.

func NewMap

func NewMap(cap int) Value

NewMap creates a new Map Value with given capacity.

func String

func String(v string) Value

String creates a string Value.

func Time

func Time(v time.Time) Value

Time creates a time.Time Value.

func (*Value) Append

func (v *Value) Append(vs ...Value)

Append appends more Values to the List Value. If the Value is not a List, it will panic.

func (Value) GoString

func (v Value) GoString() string

GoString returns a string representation of Value's data.

func (*Value) Is

func (v *Value) Is(k Kind) bool

Is returns true if the Value is of the given Kind.

func (*Value) Kind

func (v *Value) Kind() Kind

Type returns a type of the Value.

func (Value) MarshalCBOR

func (v Value) MarshalCBOR() ([]byte, error)

MarshalCBOR returns the CBOR encoding of the Value.

func (Value) MarshalJSON

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

MarshalJSON returns the JSON encoding of the Value.

func (*Value) Merge

func (v *Value) Merge(m Map)

Merge merges the given Set into the current Value. If the Value is not a Set, it will panic.

func (Value) Ptr

func (v Value) Ptr() *Value

Ptr returns the Value as a pointer.

func (*Value) Set

func (v *Value) Set(key string, value Value)

Merge merges the given Set into the current Value. If the Value is not a Set, it will panic.

func (Value) ToAny

func (v Value) ToAny() any

ToAny returns the Value as any.

func (Value) ToBigInt

func (v Value) ToBigInt() *big.Int

ToBigInt returns the *big.Int value. If Kind is not BigInt, it returns &big.Int{}.

func (Value) ToBool

func (v Value) ToBool() bool

ToBool returns the bool value. If Kind is not Bool, it returns false.

func (Value) ToFloat64

func (v Value) ToFloat64() float64

ToFloat64 returns the float64 value. If Kind is not Float64, it returns 0.

func (Value) ToInt64

func (v Value) ToInt64() int64

ToInt64 returns the int64 value. If Kind is not Int64, it returns 0.

func (*Value) ToList

func (v *Value) ToList() List

ToList returns the List value. If Kind is not List, it returns nil.

func (*Value) ToMap

func (v *Value) ToMap() Map

ToMap returns the Map value. If Kind is not Map, it returns nil.

func (Value) ToString

func (v Value) ToString() string

ToString returns the string value. If Kind is not String, it returns "".

func (Value) ToTime

func (v Value) ToTime() time.Time

ToArray returns the Array value. If Kind is not Array, it returns time.Time{}.

Jump to

Keyboard shortcuts

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