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

      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

                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

                      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

                          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

                                        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

                                                    func (v *Var) IsFloat() bool

                                                      IsFloat checks whether <v> is type of float.

                                                      func (*Var) IsInt

                                                      func (v *Var) IsInt() bool

                                                        IsInt checks whether <v> is type of int.

                                                        func (*Var) IsMap

                                                        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

                                                            func (v *Var) IsSlice() bool

                                                              IsSlice checks whether <v> is type of slice.

                                                              func (*Var) IsStruct

                                                              func (v *Var) IsStruct() bool

                                                                IsStruct checks whether <v> is type of struct.

                                                                func (*Var) IsUint

                                                                func (v *Var) IsUint() bool

                                                                  IsUint checks whether <v> is type of uint.

                                                                  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

                                                                    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

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

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

                                                                            func (*Var) MapStrStr

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

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

                                                                              func (*Var) MapStrStrDeep

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

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

                                                                                func (*Var) MapStrVar

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

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

                                                                                  func (*Var) MapStrVarDeep

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

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

                                                                                    func (*Var) MapToMap

                                                                                    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

                                                                                      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

                                                                                        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

                                                                                          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

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

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

                                                                                              func (*Var) MarshalJSON

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

                                                                                                MarshalJSON implements the interface MarshalJSON for json.Marshal.

                                                                                                func (*Var) Scan

                                                                                                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

                                                                                                  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

                                                                                                    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

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

                                                                                                                              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

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

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

                                                                                                                                    func (*Var) UnmarshalJSON

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

                                                                                                                                      UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

                                                                                                                                      func (*Var) UnmarshalValue

                                                                                                                                      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.