gutil

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComparatorByte

func ComparatorByte(a, b interface{}) int

ComparatorByte provides a basic comparison on byte.

func ComparatorFloat32

func ComparatorFloat32(a, b interface{}) int

ComparatorFloat32 provides a basic comparison on float32.

func ComparatorFloat64

func ComparatorFloat64(a, b interface{}) int

ComparatorFloat64 provides a basic comparison on float64.

func ComparatorInt

func ComparatorInt(a, b interface{}) int

ComparatorInt provides a basic comparison on int.

func ComparatorInt16

func ComparatorInt16(a, b interface{}) int

ComparatorInt16 provides a basic comparison on int16.

func ComparatorInt32

func ComparatorInt32(a, b interface{}) int

ComparatorInt32 provides a basic comparison on int32.

func ComparatorInt64

func ComparatorInt64(a, b interface{}) int

ComparatorInt64 provides a basic comparison on int64.

func ComparatorInt8

func ComparatorInt8(a, b interface{}) int

ComparatorInt8 provides a basic comparison on int8.

func ComparatorRune

func ComparatorRune(a, b interface{}) int

ComparatorRune provides a basic comparison on rune.

func ComparatorString

func ComparatorString(a, b interface{}) int

ComparatorString provides a fast comparison on strings.

func ComparatorTime

func ComparatorTime(a, b interface{}) int

ComparatorTime provides a basic comparison on time.Time.

func ComparatorUint

func ComparatorUint(a, b interface{}) int

ComparatorUint provides a basic comparison on uint.

func ComparatorUint16

func ComparatorUint16(a, b interface{}) int

ComparatorUint16 provides a basic comparison on uint16.

func ComparatorUint32

func ComparatorUint32(a, b interface{}) int

ComparatorUint32 provides a basic comparison on uint32.

func ComparatorUint64

func ComparatorUint64(a, b interface{}) int

ComparatorUint64 provides a basic comparison on uint64.

func ComparatorUint8

func ComparatorUint8(a, b interface{}) int

ComparatorUint8 provides a basic comparison on uint8.

func IsEmpty

func IsEmpty(value interface{}) bool

IsEmpty checks whether given <value> empty. It returns true if <value> is in: 0, nil, false, "", len(slice/map/chan) == 0, or else it returns false.

func ItemValue

func ItemValue(item interface{}, key interface{}) (value interface{}, found bool)

ItemValue retrieves and returns its value of which name/attribute specified by `key`. The parameter `battle` can be type of map/*map/struct/*struct.

func Keys

func Keys(mapOrStruct interface{}) (keysOrAttrs []string)

Keys retrieves and returns the keys from given map or struct.

func ListItemValues

func ListItemValues(list interface{}, key interface{}, subKey ...interface{}) (values []interface{})

ListItemValues retrieves and returns the elements of all battle 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.

The parameter `list` supports types like: []map[string]interface{} []map[string]sub-map []struct []struct:sub-struct Note that the sub-map/sub-struct makes sense only if the optional parameter `subKey` is given.

func ListItemValuesUnique

func ListItemValuesUnique(list interface{}, key string, subKey ...interface{}) []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 NiceCallFunc

func NiceCallFunc(f func())

NiceCallFunc calls function <f> with exception capture logic.

func ProtoMarshal added in v1.0.2

func ProtoMarshal(msg proto.Message) (uint32, []byte)

ProtoMarshal 获取MsgId/MsgData

func RandFloat64

func RandFloat64(min float64, max float64) float64

func RandFloat64Max

func RandFloat64Max(max float64) float64

func RandInt

func RandInt(min int, max int) int

func RandInt32

func RandInt32(min int32, max int32) int32

func RandInt32Max

func RandInt32Max(max int32) int32

func RandInt64

func RandInt64(min int64, max int64) int64

func RandInt64Max

func RandInt64Max(max int64) int64

func RandIntMax

func RandIntMax(max int) int

func RandPerm added in v1.0.1

func RandPerm(n int) []int

RandPerm returns, as a slice of n int numbers, a pseudo-random permutation of the integers [0,n).

func RandSeq

func RandSeq(size int) string

func Random

func Random() float64

func SliceCopy

func SliceCopy(data []interface{}) []interface{}

SliceCopy does a shallow copy of slice `data` for most commonly used slice type []interface{}.

func SliceDelete

func SliceDelete(data []interface{}, index int) (newSlice []interface{})

SliceDelete deletes an element at `index` and returns the new slice. It does nothing if the given `index` is invalid.

func Try

func Try(try func()) (err error)

Try implements try... logistics using internal panic...recover. It returns error if any exception occurs, or else it returns nil.

func TryCatch

func TryCatch(try func(), catch ...func(exception error))

TryCatch implements try...catch... logistics using internal panic...recover. It automatically calls function `catch` if any exception occurs ans passes the exception as an error.

func Values

func Values(mapOrStruct interface{}) (values []interface{})

Values retrieves and returns the values from given map or struct.

Types

type Comparator

type Comparator func(a, b interface{}) int

Comparator is a function that compare a and b, and returns the result as int.

Should return a number:

negative , if a < b
zero     , if a == b
positive , if a > b

type Jwt

type Jwt struct {
	Field string
	Key   []byte
	Ttl   int64
}

func (*Jwt) Decode

func (j *Jwt) Decode(auth string) (fieldValue interface{}, err error)

func (*Jwt) DecodeInt

func (j *Jwt) DecodeInt(auth string) (fieldValue int, err error)

func (*Jwt) DecodeInt32

func (j *Jwt) DecodeInt32(auth string) (fieldValue int32, err error)

func (*Jwt) DecodeInt64

func (j *Jwt) DecodeInt64(auth string) (fieldValue int64, err error)

func (*Jwt) DecodeInt8

func (j *Jwt) DecodeInt8(auth string) (fieldValue int8, err error)

func (*Jwt) DecodeString

func (j *Jwt) DecodeString(auth string) (fieldValue string, err error)

func (*Jwt) DecodeUint

func (j *Jwt) DecodeUint(auth string) (fieldValue uint, err error)

func (*Jwt) DecodeUint32

func (j *Jwt) DecodeUint32(auth string) (fieldValue uint32, err error)

func (*Jwt) DecodeUint64

func (j *Jwt) DecodeUint64(auth string) (fieldValue uint64, err error)

func (*Jwt) DecodeUint8

func (j *Jwt) DecodeUint8(auth string) (fieldValue uint8, err error)

func (*Jwt) Encode

func (j *Jwt) Encode(fieldValue interface{}) string

Jump to

Keyboard shortcuts

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