gf: github.com/gogf/gf/container/gvar Index | Files

package gvar

import "github.com/gogf/gf/container/gvar"

Package gvar provides an universal variable type, like generics.

Index

Package Files

gvar.go gvar_list.go gvar_map.go gvar_struct.go

type Var Uses

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

Var is an universal variable type implementer.

func Create Uses

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 Uses

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 Uses

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

Array is alias of Interfaces.

func (*Var) Bool Uses

func (v *Var) Bool() bool

Bool converts and returns <v> as bool.

func (*Var) Bytes Uses

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

Bytes converts and returns <v> as []byte.

func (*Var) Clone Uses

func (v *Var) Clone() *Var

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

func (*Var) Duration Uses

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 Uses

func (v *Var) Float32() float32

Float32 converts and returns <v> as float32.

func (*Var) Float64 Uses

func (v *Var) Float64() float64

Float64 converts and returns <v> as float64.

func (*Var) Floats Uses

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

Floats converts and returns <v> as []float64.

func (*Var) GTime Uses

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 Uses

func (v *Var) Int() int

Int converts and returns <v> as int.

func (*Var) Int16 Uses

func (v *Var) Int16() int16

Int16 converts and returns <v> as int16.

func (*Var) Int32 Uses

func (v *Var) Int32() int32

Int32 converts and returns <v> as int32.

func (*Var) Int64 Uses

func (v *Var) Int64() int64

Int64 converts and returns <v> as int64.

func (*Var) Int8 Uses

func (v *Var) Int8() int8

Int8 converts and returns <v> as int8.

func (*Var) Interface Uses

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

Interface is alias of Val.

func (*Var) Interfaces Uses

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

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

func (*Var) Ints Uses

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

Ints converts and returns <v> as []int.

func (*Var) IsEmpty Uses

func (v *Var) IsEmpty() bool

IsEmpty checks whether <v> is empty.

func (*Var) IsNil Uses

func (v *Var) IsNil() bool

IsNil checks whether <v> is nil.

func (*Var) ListItemValues Uses

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 Uses

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 Uses

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

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

func (*Var) MapDeep Uses

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

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

func (*Var) MapStrAny Uses

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

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

func (*Var) MapStrStr Uses

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

MapStrStr converts and returns <v> as map[string]string.

func (*Var) MapStrStrDeep Uses

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

MapDeep converts and returns <v> as map[string]string recursively.

func (*Var) MapStrVar Uses

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

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

func (*Var) MapStrVarDeep Uses

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

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

func (*Var) MapToMap Uses

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) MapToMapDeep Uses

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

MapToMapDeep converts any map type variable <params> to another map type variable <pointer> recursively. See gconv.MapToMapDeep.

func (*Var) MapToMaps Uses

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 Uses

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 Uses

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

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

func (*Var) MarshalJSON Uses

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*Var) Scan Uses

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 Uses

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.

func (*Var) Set Uses

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

Set sets <value> to <v>, and returns the old value.

func (*Var) Slice Uses

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

Slice is alias of Interfaces.

func (*Var) String Uses

func (v *Var) String() string

String converts and returns <v> as string.

func (*Var) Strings Uses

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

Strings converts and returns <v> as []string.

func (*Var) Struct Uses

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 Uses

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

Struct 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.

func (*Var) Structs Uses

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

Structs converts and returns <v> as given struct slice.

func (*Var) StructsDeep Uses

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

StructsDeep converts and returns <v> as given struct slice recursively.

func (*Var) Time Uses

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 Uses

func (v *Var) Uint() uint

Uint converts and returns <v> as uint.

func (*Var) Uint16 Uses

func (v *Var) Uint16() uint16

Uint16 converts and returns <v> as uint16.

func (*Var) Uint32 Uses

func (v *Var) Uint32() uint32

Uint32 converts and returns <v> as uint32.

func (*Var) Uint64 Uses

func (v *Var) Uint64() uint64

Uint64 converts and returns <v> as uint64.

func (*Var) Uint8 Uses

func (v *Var) Uint8() uint8

Uint8 converts and returns <v> as uint8.

func (*Var) Uints Uses

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

Uints converts and returns <v> as []uint.

func (*Var) UnmarshalJSON Uses

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

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

func (*Var) UnmarshalValue Uses

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

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

func (*Var) Val Uses

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

Val returns the current value of <v>.

func (*Var) Vars Uses

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

Vars converts and returns <v> as []Var.

Package gvar imports 7 packages (graph) and is imported by 14 packages. Updated 2020-07-07. Refresh now. Tools for package owners.