gvar

package
v1.9.4 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2019 License: MIT Imports: 6 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.

func New

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

New returns a new Var with given <value>. The parameter <safe> used to specify whether using Var 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) 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) Float64

func (v *Var) Float64() float64

Float64 converts and returns <v> as float64.

func (*Var) Floats

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

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

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) 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) IsNil

func (v *Var) IsNil() bool

IsNil checks whether <v> is nil.

func (*Var) Map

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

Map converts <v> to map[string]interface{}.

func (*Var) MapDeep

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

MapDeep converts <v> to map[string]interface{} recursively.

func (*Var) MapStrStr added in v1.9.3

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

MapStrStr converts <v> to map[string]string.

func (*Var) MapStrStrDeep added in v1.9.3

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

MapDeep converts <v> to map[string]string recursively.

func (*Var) MapStrVar added in v1.9.3

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

MapStrVar converts <v> to map[string]*Var.

func (*Var) MapStrVarDeep added in v1.9.3

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

MapStrVarDeep converts <v> to 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 map type variable <params> to another map type variable <pointer>. The elements of <pointer> should be type of struct/*struct.

func (*Var) MapToMapDeep added in v1.9.3

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

MapToMapDeep recursively converts map type variable <params> to another map type variable <pointer>. The elements of <pointer> should be type of struct/*struct.

func (*Var) MapToMaps added in v1.9.3

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

MapToMaps converts map type variable <params> to another map type variable <pointer>. The elements of <pointer> should be type of []struct/[]*struct.

func (*Var) MapToMapsDeep added in v1.9.3

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

MapToMapsDeep recursively converts map type variable <params> to another map type variable <pointer>. The elements of <pointer> should be type of []struct/[]*struct.

func (*Var) MarshalJSON

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

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.

func (*Var) Structs

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

Structs converts <v> to given struct slice.

func (*Var) StructsDeep

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

StructsDeep converts <v> to given struct slice recursively.

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) Uint8

func (v *Var) Uint8() uint8

Uint8 converts and returns <v> as uint8.

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