gvalue

package
v0.0.0-...-37ff87a Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2024 License: MIT Imports: 11 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains(sliceInterface interface{}, value interface{}) bool

Contains check the input slice if contains the value

func FormatByteSize

func FormatByteSize(v uint64) string

FormatByteSize convert byte size v to human-readable format, for example 1024 -> 1K

func FormatNumber

func FormatNumber(v interface{}) string

FormatNumber return split by comma format of number v. v must be intX, uintX or intX string, uintX string, example: 10000 -> 10,000

func IndexOf

func IndexOf(sliceInterface interface{}, value interface{}) int

IndexOf returns the index of value in slice, if not found -1 returned

func IsEmpty

func IsEmpty(object interface{}) bool

IsEmpty if object is IsNil with true, or is empty string, return true, others false.

func IsNil

func IsNil(object interface{}) bool

IsNil if object is nil or a nil pointer variable or nil builtin pointer variable(chan,func,interface,map,ptr,slice) return true, others false.

func MapToStruct

func MapToStruct(mapData map[string]interface{}, _value interface{}) (newStruct interface{}, err error)

MapToStruct same with MapToStructWithTag, but `json` is used as tag name by default

func MapToStructWithTag

func MapToStructWithTag(mapData map[string]interface{}, _value interface{}, tag string) (newStruct interface{}, err error)

MapToStructWithTag convert map to struct, _value is a pointer to strut, if key 'tag' not exists in the map, the filed name will used as map key. Returned newStruct is a struct, for example: newStruct.(User) to assert it type. Details refer to TestMapToStruct. Ignore filed, set tag tagName:"-", for example: User{ Age int `tagName:"-"` }

func ParseByteSize

func ParseByteSize(v string) uint64

ParseByteSize convert human-readable byte size format v to byte size, v can be: 1, 1B, 1KB, 1.1KB, 1MB, 1GB, 1TB, 1PB, 1EB

func ParseNumber

func ParseNumber(v string) int64

ParseNumber convert human-readable number format v to int64, example: 100,123 -> 100123

Types

type AnyValue

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

func Keys

func Keys(_map interface{}) *AnyValue

Keys input _map is a map, returns its keys as slice, AnyValue.xxxSlice to get the typed slice.

func MustAny

func MustAny(v interface{}, err error) (value *AnyValue)

MustAny ignore err, return *AnyValue of v

func NewAny

func NewAny(val interface{}) *AnyValue

NewAny wrap the val with type *AnyValue, *AnyValue.XXX() convert val to type XXX.

func (*AnyValue) Bool

func (s *AnyValue) Bool() bool

func (*AnyValue) BoolSlice

func (s *AnyValue) BoolSlice() []bool

func (*AnyValue) Bytes

func (s *AnyValue) Bytes() []byte

func (*AnyValue) Duration

func (s *AnyValue) Duration() time.Duration

func (*AnyValue) DurationSlice

func (s *AnyValue) DurationSlice() []time.Duration

func (*AnyValue) Float32

func (s *AnyValue) Float32() float32

func (*AnyValue) Float32Slice

func (s *AnyValue) Float32Slice() []float32

func (*AnyValue) Float64

func (s *AnyValue) Float64() float64

func (*AnyValue) Float64Slice

func (s *AnyValue) Float64Slice() []float64

func (*AnyValue) Int

func (s *AnyValue) Int() int

func (*AnyValue) Int32

func (s *AnyValue) Int32() int32

func (*AnyValue) Int32Slice

func (s *AnyValue) Int32Slice() []int32

func (*AnyValue) Int64

func (s *AnyValue) Int64() int64

func (*AnyValue) Int64Slice

func (s *AnyValue) Int64Slice() []int64

func (*AnyValue) Int8

func (s *AnyValue) Int8() int8

func (*AnyValue) Int8Slice

func (s *AnyValue) Int8Slice() []int8

func (*AnyValue) IntSlice

func (s *AnyValue) IntSlice() []int

func (*AnyValue) Map

func (s *AnyValue) Map() map[string]interface{}

func (*AnyValue) MapBool

func (s *AnyValue) MapBool() map[string]bool

func (*AnyValue) MapFloat32

func (s *AnyValue) MapFloat32() map[string]float32

func (*AnyValue) MapFloat64

func (s *AnyValue) MapFloat64() map[string]float64

func (*AnyValue) MapInt

func (s *AnyValue) MapInt() map[string]int

func (*AnyValue) MapInt32

func (s *AnyValue) MapInt32() map[string]int32

func (*AnyValue) MapInt64

func (s *AnyValue) MapInt64() map[string]int64

func (*AnyValue) MapInt8

func (s *AnyValue) MapInt8() map[string]int8

func (*AnyValue) MapString

func (s *AnyValue) MapString() map[string]string

func (*AnyValue) MapUint

func (s *AnyValue) MapUint() map[string]uint

func (*AnyValue) MapUint32

func (s *AnyValue) MapUint32() map[string]uint32

func (*AnyValue) MapUint64

func (s *AnyValue) MapUint64() map[string]uint64

func (*AnyValue) MapUint8

func (s *AnyValue) MapUint8() map[string]uint8

func (*AnyValue) Slice

func (s *AnyValue) Slice() []interface{}

func (*AnyValue) String

func (s *AnyValue) String() string

func (*AnyValue) StringSlice

func (s *AnyValue) StringSlice() []string

func (*AnyValue) Time

func (s *AnyValue) Time() time.Time

func (*AnyValue) Uint

func (s *AnyValue) Uint() uint

func (*AnyValue) Uint32

func (s *AnyValue) Uint32() uint32

func (*AnyValue) Uint32Slice

func (s *AnyValue) Uint32Slice() []uint32

func (*AnyValue) Uint64

func (s *AnyValue) Uint64() uint64

func (*AnyValue) Uint64Slice

func (s *AnyValue) Uint64Slice() []uint64

func (*AnyValue) Uint8

func (s *AnyValue) Uint8() uint8

func (*AnyValue) Uint8Slice

func (s *AnyValue) Uint8Slice() []uint8

func (*AnyValue) UintSlice

func (s *AnyValue) UintSlice() []uint

func (*AnyValue) Val

func (s *AnyValue) Val() interface{}

type Value

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

func GetValueAt

func GetValueAt(sliceOrArray interface{}, idx int, defaultValue interface{}) *Value

GetValueAt sliceOrArray is slice or array, idx is the element to get, if idx invalid or sliceOrArray is not slice or array, the default value will be used

func Must

func Must(v interface{}, err error) (value *Value)

Must ignore err, return *Must of v

func New

func New(val interface{}) *Value

New wrap the val with type *Value, type val and *Value.XXX() must be same.

func (*Value) Bool

func (s *Value) Bool() bool

func (*Value) Bytes

func (s *Value) Bytes() []byte

func (*Value) Duration

func (s *Value) Duration() time.Duration

func (*Value) Float32

func (s *Value) Float32() float32

func (*Value) Float64

func (s *Value) Float64() float64

func (*Value) Int

func (s *Value) Int() int

func (*Value) Int32

func (s *Value) Int32() int32

func (*Value) Int64

func (s *Value) Int64() int64

func (*Value) Int8

func (s *Value) Int8() int8

func (*Value) Map

func (s *Value) Map() map[string]interface{}

func (*Value) MapBool

func (s *Value) MapBool() map[string]bool

func (*Value) MapFloat32

func (s *Value) MapFloat32() map[string]float32

func (*Value) MapFloat64

func (s *Value) MapFloat64() map[string]float64

func (*Value) MapInt

func (s *Value) MapInt() map[string]int

func (*Value) MapInt32

func (s *Value) MapInt32() map[string]int32

func (*Value) MapInt64

func (s *Value) MapInt64() map[string]int64

func (*Value) MapInt8

func (s *Value) MapInt8() map[string]int8

func (*Value) MapSlice

func (s *Value) MapSlice() map[string][]interface{}

func (*Value) MapString

func (s *Value) MapString() map[string]string

func (*Value) MapStringSlice

func (s *Value) MapStringSlice() map[string][]string

func (*Value) MapUint

func (s *Value) MapUint() map[string]uint

func (*Value) MapUint32

func (s *Value) MapUint32() map[string]uint32

func (*Value) MapUint64

func (s *Value) MapUint64() map[string]uint64

func (*Value) MapUint8

func (s *Value) MapUint8() map[string]uint8

func (*Value) Slice

func (s *Value) Slice() []interface{}

func (*Value) String

func (s *Value) String() string

func (*Value) StringSlice

func (s *Value) StringSlice() []string

func (*Value) Time

func (s *Value) Time() time.Time

func (*Value) Uint

func (s *Value) Uint() uint

func (*Value) Uint32

func (s *Value) Uint32() uint32

func (*Value) Uint64

func (s *Value) Uint64() uint64

func (*Value) Uint8

func (s *Value) Uint8() uint8

func (*Value) Val

func (s *Value) Val() interface{}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL