types

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2023 License: MIT Imports: 7 Imported by: 0

README

types

Type casting and conversion in Go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dictionary

type Dictionary map[string]Variant

func (Dictionary) Get

func (d Dictionary) Get(key string) Variant

func (Dictionary) Set

func (d Dictionary) Set(key string, v any)

type KV

type KV map[string]any

KV key value data

func (KV) Bool

func (k KV) Bool(key string, def ...bool) bool

func (KV) Duration

func (k KV) Duration(key string, def ...time.Duration) time.Duration

func (KV) Float

func (k KV) Float(key string, def ...float64) float64

func (KV) Int

func (k KV) Int(key string, def ...int) int

func (KV) String

func (k KV) String(key string, def ...string) string

func (KV) Time

func (k KV) Time(key string, def ...time.Time) time.Time

func (KV) Uint

func (k KV) Uint(key string, def ...uint) uint

func (KV) V

func (k KV) V(key string) RVariant

type RVariant

type RVariant interface {
	IsNil() bool
	IsZero() bool
	Uint8E() (uint8, error)
	Uint16E() (uint16, error)
	Uint32E() (uint32, error)
	Uint64E() (uint64, error)
	UintE() (uint, error)
	Int8E() (int8, error)
	Int16E() (int16, error)
	Int32E() (int32, error)
	Int64E() (int64, error)
	IntE() (int, error)
	ByteE() (byte, error)
	Float32E() (float32, error)
	Float64E() (float64, error)
	BoolE() (bool, error)
	StringE() (string, error)
	DurationE() (time.Duration, error)
	TimeE() (time.Time, error)
	Interface() any

	Uint8() uint8
	Uint16() uint16
	Uint32() uint32
	Uint64() uint64
	Uint() uint
	Int8() int8
	Int16() int16
	Int32() int32
	Int64() int64
	Int() int
	Byte() byte
	Float32() float32
	Float64() float64
	Bool() bool
	String() string
	Duration() time.Duration
	Time() time.Time

	Value() (driver.Value, error)
	MarshalJSON() ([]byte, error)
}

RVariant holds various value and handle type conversion.

For conversion to time.Duration and time.Time, if value type is floating point, e.g. nnn.fff then nnn will be treated as seconds, while fff will be treated as nano seconds.

func NewRVariant

func NewRVariant(i interface{}) RVariant

NewRVariant create readonly variant from given value

type Scalar

type Scalar interface {
	constraints.Float | constraints.Integer
}

Scalar number constraint

type Variant

type Variant interface {
	RVariant

	Set(v any) error
	UnmarshalJSON(data []byte) error
	Scan(src any) error
}

Variant is a variant that can be modified

func NewVariant

func NewVariant(i ...interface{}) Variant

NewVariant create r/w variant from optionally given value

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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