gvar

package
v1.16.9 Latest Latest
Warning

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

Go to latest
Published: May 30, 2022 License: MIT Imports: 7 Imported by: 64

Documentation

Overview

Package gvar provides an universal variable type, like generics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Var

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

Var is an universal variable type implementer.

func Create added in v1.9.7

func Create(value interface{}, safe ...bool) Var

Create creates and returns a new Var with given `value`. The optional parameter `safe` specifies whether Var is used in concurrent-safety, which is false in default.

func New

func New(value interface{}, safe ...bool) *Var

New creates and returns a new Var with given `value`. The optional parameter `safe` specifies whether Var is used in concurrent-safety, which is false in default.

func (*Var) Array

func (v *Var) Array() []interface{}

Array is alias of Interfaces.

func (*Var) Bool

func (v *Var) Bool() bool

Bool converts and returns `v` as bool.

func (*Var) Bytes

func (v *Var) Bytes() []byte

Bytes converts and returns `v` as []byte.

func (*Var) Clone added in v1.12.0

func (v *Var) Clone() *Var

Clone does a shallow copy of current Var and returns a pointer to this Var.

func (*Var) Duration

func (v *Var) Duration() time.Duration

Duration converts and returns `v` as time.Duration. If value of `v` is string, then it uses time.ParseDuration for conversion.

func (*Var) Float32

func (v *Var) Float32() float32

Float32 converts and returns `v` as float32.

func (*Var) Float32s added in v1.15.2

func (v *Var) Float32s() []float32

Float32s converts and returns `v` as []float32.

func (*Var) Float64

func (v *Var) Float64() float64

Float64 converts and returns `v` as float64.

func (*Var) Float64s added in v1.15.2

func (v *Var) Float64s() []float64

Float64s converts and returns `v` as []float64.

func (*Var) Floats

func (v *Var) Floats() []float64

Floats is alias of Float64s.

func (*Var) GTime

func (v *Var) GTime(format ...string) *gtime.Time

GTime converts and returns `v` as *gtime.Time. The parameter `format` specifies the format of the time string using gtime, eg: Y-m-d H:i:s.

func (*Var) Int

func (v *Var) Int() int

Int converts and returns `v` as int.

func (*Var) Int16

func (v *Var) Int16() int16

Int16 converts and returns `v` as int16.

func (*Var) Int32

func (v *Var) Int32() int32

Int32 converts and returns `v` as int32.

func (*Var) Int64

func (v *Var) Int64() int64

Int64 converts and returns `v` as int64.

func (*Var) Int64s added in v1.15.2

func (v *Var) Int64s() []int64

Int64s converts and returns `v` as []int64.

func (*Var) Int8

func (v *Var) Int8() int8

Int8 converts and returns `v` as int8.

func (*Var) Interface

func (v *Var) Interface() interface{}

Interface is alias of Val.

func (*Var) Interfaces

func (v *Var) Interfaces() []interface{}

Interfaces converts and returns `v` as []interfaces{}.

func (*Var) Ints

func (v *Var) Ints() []int

Ints converts and returns `v` as []int.

func (*Var) IsEmpty

func (v *Var) IsEmpty() bool

IsEmpty checks whether `v` is empty.

func (*Var) IsFloat added in v1.14.6

func (v *Var) IsFloat() bool

IsFloat checks whether `v` is type of float.

func (*Var) IsInt added in v1.14.6

func (v *Var) IsInt() bool

IsInt checks whether `v` is type of int.

func (*Var) IsMap added in v1.14.6

func (v *Var) IsMap() bool

IsMap checks whether `v` is type of map.

func (*Var) IsNil

func (v *Var) IsNil() bool

IsNil checks whether `v` is nil.

func (*Var) IsSlice added in v1.14.6

func (v *Var) IsSlice() bool

IsSlice checks whether `v` is type of slice.

func (*Var) IsStruct added in v1.14.6

func (v *Var) IsStruct() bool

IsStruct checks whether `v` is type of struct.

func (*Var) IsUint added in v1.14.6

func (v *Var) IsUint() bool

IsUint checks whether `v` is type of uint.

func (*Var) ListItemValues added in v1.13.2

func (v *Var) ListItemValues(key interface{}) (values []interface{})

ListItemValues retrieves and returns the elements of all item struct/map with key `key`. Note that the parameter `list` should be type of slice which contains elements of map or struct, or else it returns an empty slice.

func (*Var) ListItemValuesUnique added in v1.13.2

func (v *Var) ListItemValuesUnique(key string) []interface{}

ListItemValuesUnique retrieves and returns the unique elements of all struct/map with key `key`. Note that the parameter `list` should be type of slice which contains elements of map or struct, or else it returns an empty slice.

func (*Var) Map

func (v *Var) Map(tags ...string) map[string]interface{}

Map converts and returns `v` as map[string]interface{}.

func (*Var) MapDeep

func (v *Var) MapDeep(tags ...string) map[string]interface{}

MapDeep converts and returns `v` as map[string]interface{} recursively.

func (*Var) MapStrAny added in v1.13.2

func (v *Var) MapStrAny() map[string]interface{}

MapStrAny is like function Map, but implements the interface of MapStrAny.

func (*Var) MapStrStr added in v1.9.3

func (v *Var) MapStrStr(tags ...string) map[string]string

MapStrStr converts and returns `v` as map[string]string.

func (*Var) MapStrStrDeep added in v1.9.3

func (v *Var) MapStrStrDeep(tags ...string) map[string]string

MapStrStrDeep converts and returns `v` as map[string]string recursively.

func (*Var) MapStrVar added in v1.9.3

func (v *Var) MapStrVar(tags ...string) map[string]*Var

MapStrVar converts and returns `v` as map[string]Var.

func (*Var) MapStrVarDeep added in v1.9.3

func (v *Var) MapStrVarDeep(tags ...string) map[string]*Var

MapStrVarDeep converts and returns `v` as map[string]*Var recursively.

func (*Var) MapToMap added in v1.9.3

func (v *Var) MapToMap(pointer interface{}, mapping ...map[string]string) (err error)

MapToMap converts any map type variable `params` to another map type variable `pointer`. See gconv.MapToMap.

func (*Var) MapToMaps added in v1.9.3

func (v *Var) MapToMaps(pointer interface{}, mapping ...map[string]string) (err error)

MapToMaps converts any map type variable `params` to another map type variable `pointer`. See gconv.MapToMaps.

func (*Var) MapToMapsDeep added in v1.9.3

func (v *Var) MapToMapsDeep(pointer interface{}, mapping ...map[string]string) (err error)

MapToMapsDeep converts any map type variable `params` to another map type variable `pointer` recursively. See gconv.MapToMapsDeep.

func (*Var) Maps added in v1.12.3

func (v *Var) Maps(tags ...string) []map[string]interface{}

Maps converts and returns `v` as map[string]string. See gconv.Maps.

func (*Var) MapsDeep added in v1.16.6

func (v *Var) MapsDeep(tags ...string) []map[string]interface{}

MapsDeep converts `value` to []map[string]interface{} recursively. See gconv.MapsDeep.

func (*Var) MarshalJSON

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*Var) Scan added in v1.13.2

func (v *Var) Scan(pointer interface{}, mapping ...map[string]string) error

Scan automatically calls Struct or Structs function according to the type of parameter `pointer` to implement the converting.

It calls function Struct if `pointer` is type of *struct/**struct to do the converting. It calls function Structs if `pointer` is type of *[]struct/*[]*struct to do the converting.

func (*Var) ScanDeep added in v1.13.2

func (v *Var) ScanDeep(pointer interface{}, mapping ...map[string]string) error

ScanDeep automatically calls StructDeep or StructsDeep function according to the type of parameter `pointer` to implement the converting.

It calls function StructDeep if `pointer` is type of *struct/**struct to do the converting. It calls function StructsDeep if `pointer` is type of *[]struct/*[]*struct to do the converting.

Deprecated, use Scan instead.

func (*Var) Set

func (v *Var) Set(value interface{}) (old interface{})

Set sets `value` to `v`, and returns the old value.

func (*Var) Slice

func (v *Var) Slice() []interface{}

Slice is alias of Interfaces.

func (*Var) String

func (v *Var) String() string

String converts and returns `v` as string.

func (*Var) Strings

func (v *Var) Strings() []string

Strings converts and returns `v` as []string.

func (*Var) Struct

func (v *Var) Struct(pointer interface{}, mapping ...map[string]string) error

Struct maps value of `v` to `pointer`. The parameter `pointer` should be a pointer to a struct instance. The parameter `mapping` is used to specify the key-to-attribute mapping rules.

func (*Var) StructDeep

func (v *Var) StructDeep(pointer interface{}, mapping ...map[string]string) error

StructDeep maps value of `v` to `pointer` recursively. The parameter `pointer` should be a pointer to a struct instance. The parameter `mapping` is used to specify the key-to-attribute mapping rules. Deprecated, use Struct instead.

func (*Var) Structs

func (v *Var) Structs(pointer interface{}, mapping ...map[string]string) error

Structs converts and returns `v` as given struct slice.

func (*Var) StructsDeep

func (v *Var) StructsDeep(pointer interface{}, mapping ...map[string]string) error

StructsDeep converts and returns `v` as given struct slice recursively. Deprecated, use Struct instead.

func (*Var) Time

func (v *Var) Time(format ...string) time.Time

Time converts and returns `v` as time.Time. The parameter `format` specifies the format of the time string using gtime, eg: Y-m-d H:i:s.

func (*Var) Uint

func (v *Var) Uint() uint

Uint converts and returns `v` as uint.

func (*Var) Uint16

func (v *Var) Uint16() uint16

Uint16 converts and returns `v` as uint16.

func (*Var) Uint32

func (v *Var) Uint32() uint32

Uint32 converts and returns `v` as uint32.

func (*Var) Uint64

func (v *Var) Uint64() uint64

Uint64 converts and returns `v` as uint64.

func (*Var) Uint64s added in v1.15.2

func (v *Var) Uint64s() []uint64

Uint64s converts and returns `v` as []uint64.

func (*Var) Uint8

func (v *Var) Uint8() uint8

Uint8 converts and returns `v` as uint8.

func (*Var) Uints added in v1.9.7

func (v *Var) Uints() []uint

Uints converts and returns `v` as []uint.

func (*Var) UnmarshalJSON added in v1.9.7

func (v *Var) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

func (*Var) UnmarshalValue added in v1.11.5

func (v *Var) UnmarshalValue(value interface{}) error

UnmarshalValue is an interface implement which sets any type of value for Var.

func (*Var) Val

func (v *Var) Val() interface{}

Val returns the current value of `v`.

func (*Var) Vars

func (v *Var) Vars() []*Var

Vars converts and returns `v` as []Var.

Jump to

Keyboard shortcuts

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