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) Float32s() []float32
- func (v *Var) Float64() float64
- func (v *Var) Float64s() []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) Int64s() []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) IsFloat() bool
- func (v *Var) IsInt() bool
- func (v *Var) IsMap() bool
- func (v *Var) IsNil() bool
- func (v *Var) IsSlice() bool
- func (v *Var) IsStruct() bool
- func (v *Var) IsUint() 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) 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) MapsDeep(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) 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) Structs(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) Uint64s() []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 ¶
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) 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 ¶
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 ¶
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) MapStrStrDeep ¶
MapStrStrDeep converts and returns `v` as map[string]string recursively.
func (*Var) MapStrVarDeep ¶
MapStrVarDeep converts and returns `v` as map[string]*Var recursively.
func (*Var) MapToMap ¶
MapToMap converts any map type variable `params` to another map type variable `pointer`. See gconv.MapToMap.
func (*Var) MapToMaps ¶
MapToMaps converts any map type variable `params` to another map type variable `pointer`. See gconv.MapToMaps.
func (*Var) MapToMapsDeep ¶
MapToMapsDeep converts any map type variable `params` to another map type variable `pointer` recursively. See gconv.MapToMapsDeep.
func (*Var) MapsDeep ¶
MapsDeep converts `value` to []map[string]interface{} recursively. See gconv.MapsDeep.
func (*Var) MarshalJSON ¶
MarshalJSON implements the interface MarshalJSON for json.Marshal.
func (*Var) Scan ¶
Scan automatically checks the type of `pointer` and converts `params` to `pointer`. It supports `pointer` with type of `*map/*[]map/*[]*map/*struct/**struct/*[]struct/*[]*struct` for converting.
See gconv.Scan.
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) 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 ¶
UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
func (*Var) UnmarshalValue ¶
UnmarshalValue is an interface implement which sets any type of value for Var.