Documentation ¶
Overview ¶
Package gvar provides an universal variable type, like generics.
Index ¶
- type Var
- func (v *Var) Array() []interface{}
- func (v *Var) Bool() bool
- func (v *Var) Bytes() []byte
- func (v *Var) Clone() *Var
- func (v *Var) Duration() time.Duration
- func (v *Var) Float32() float32
- func (v *Var) Float64() float64
- func (v *Var) Floats() []float64
- func (v *Var) GTime(format ...string) *gtime.Time
- func (v *Var) Int() int
- func (v *Var) Int16() int16
- func (v *Var) Int32() int32
- func (v *Var) Int64() int64
- func (v *Var) Int8() int8
- func (v *Var) Interface() interface{}
- func (v *Var) Interfaces() []interface{}
- func (v *Var) Ints() []int
- func (v *Var) IsEmpty() bool
- func (v *Var) IsNil() bool
- func (v *Var) ListItemValues(key interface{}) (values []interface{})
- func (v *Var) ListItemValuesUnique(key string) []interface{}
- func (v *Var) Map(tags ...string) map[string]interface{}
- func (v *Var) MapDeep(tags ...string) map[string]interface{}
- func (v *Var) MapStrAny() map[string]interface{}
- func (v *Var) MapStrStr(tags ...string) map[string]string
- func (v *Var) MapStrStrDeep(tags ...string) map[string]string
- func (v *Var) MapStrVar(tags ...string) map[string]*Var
- func (v *Var) MapStrVarDeep(tags ...string) map[string]*Var
- func (v *Var) MapToMap(pointer interface{}, mapping ...map[string]string) (err error)
- func (v *Var) MapToMapDeep(pointer interface{}, mapping ...map[string]string) (err error)
- func (v *Var) MapToMaps(pointer interface{}, mapping ...map[string]string) (err error)
- func (v *Var) MapToMapsDeep(pointer interface{}, mapping ...map[string]string) (err error)
- func (v *Var) Maps(tags ...string) []map[string]interface{}
- func (v *Var) MarshalJSON() ([]byte, error)
- func (v *Var) Scan(pointer interface{}, mapping ...map[string]string) error
- func (v *Var) ScanDeep(pointer interface{}, mapping ...map[string]string) error
- func (v *Var) Set(value interface{}) (old interface{})
- func (v *Var) Slice() []interface{}
- func (v *Var) String() string
- func (v *Var) Strings() []string
- func (v *Var) Struct(pointer interface{}, mapping ...map[string]string) error
- func (v *Var) StructDeep(pointer interface{}, mapping ...map[string]string) error
- func (v *Var) Structs(pointer interface{}, mapping ...map[string]string) error
- func (v *Var) StructsDeep(pointer interface{}, mapping ...map[string]string) error
- func (v *Var) Time(format ...string) time.Time
- func (v *Var) Uint() uint
- func (v *Var) Uint16() uint16
- func (v *Var) Uint32() uint32
- func (v *Var) Uint64() uint64
- func (v *Var) Uint8() uint8
- func (v *Var) Uints() []uint
- func (v *Var) UnmarshalJSON(b []byte) error
- func (v *Var) UnmarshalValue(value interface{}) error
- func (v *Var) Val() interface{}
- func (v *Var) Vars() []*Var
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
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 ¶
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) Clone ¶ added in v1.12.0
Clone does a shallow copy of current Var and returns a pointer to this Var.
func (*Var) Duration ¶
Duration converts and returns <v> as time.Duration. If value of <v> is string, then it uses time.ParseDuration for conversion.
func (*Var) GTime ¶
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) Interfaces ¶
func (v *Var) Interfaces() []interface{}
Interfaces converts and returns <v> as []interfaces{}.
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
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) MapStrAny ¶ added in v1.13.2
MapStrAny is like function Map, but implements the interface of MapStrAny.
func (*Var) MapStrStrDeep ¶ added in v1.9.3
MapDeep converts and returns <v> as map[string]string recursively.
func (*Var) MapStrVarDeep ¶ added in v1.9.3
MapStrVarDeep converts and returns <v> as map[string]*Var recursively.
func (*Var) MapToMap ¶ added in v1.9.3
MapToMap converts any map type variable <params> to another map type variable <pointer>. See gconv.MapToMap.
func (*Var) MapToMapDeep ¶ added in v1.9.3
MapToMapDeep converts any map type variable <params> to another map type variable <pointer> recursively. See gconv.MapToMapDeep.
func (*Var) MapToMaps ¶ added in v1.9.3
MapToMaps converts any map type variable <params> to another map type variable <pointer>. See gconv.MapToMaps.
func (*Var) MapToMapsDeep ¶ added in v1.9.3
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
Maps converts and returns <v> as map[string]string. See gconv.Maps.
func (*Var) MarshalJSON ¶
MarshalJSON implements the interface MarshalJSON for json.Marshal.
func (*Var) Scan ¶ added in v1.13.2
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
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 ¶
func (v *Var) Set(value interface{}) (old interface{})
Set sets <value> to <v>, and returns the old value.
func (*Var) Struct ¶
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 ¶
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) StructsDeep ¶
StructsDeep converts and returns <v> as given struct slice recursively.
func (*Var) 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) UnmarshalJSON ¶ added in v1.9.7
UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
func (*Var) UnmarshalValue ¶ added in v1.11.5
UnmarshalValue is an interface implement which sets any type of value for Var.