Documentation ¶
Overview ¶
Package gutil provides utility functions.
Index ¶
- func ComparatorByte(a, b interface{}) int
- func ComparatorFloat32(a, b interface{}) int
- func ComparatorFloat64(a, b interface{}) int
- func ComparatorInt(a, b interface{}) int
- func ComparatorInt16(a, b interface{}) int
- func ComparatorInt32(a, b interface{}) int
- func ComparatorInt64(a, b interface{}) int
- func ComparatorInt8(a, b interface{}) int
- func ComparatorRune(a, b interface{}) int
- func ComparatorString(a, b interface{}) int
- func ComparatorTime(a, b interface{}) int
- func ComparatorUint(a, b interface{}) int
- func ComparatorUint16(a, b interface{}) int
- func ComparatorUint32(a, b interface{}) int
- func ComparatorUint64(a, b interface{}) int
- func ComparatorUint8(a, b interface{}) int
- func Dump(i ...interface{})
- func Export(i ...interface{}) string
- func IsEmpty(value interface{}) bool
- func ItemValue(item interface{}, key interface{}) (value interface{})
- func ListItemValues(list interface{}, key interface{}, subKey ...interface{}) (values []interface{})
- func ListItemValuesUnique(list interface{}, key string, subKey ...interface{}) []interface{}
- func MapContains(data map[string]interface{}, key string) (ok bool)
- func MapContainsPossibleKey(data map[string]interface{}, key string) bool
- func MapCopy(data map[string]interface{}) (copy map[string]interface{})
- func MapDelete(data map[string]interface{}, keys ...string)
- func MapMerge(dst map[string]interface{}, src ...map[string]interface{})
- func MapMergeCopy(src ...map[string]interface{}) (copy map[string]interface{})
- func MapPossibleItemByKey(data map[string]interface{}, key string) (foundKey string, foundValue interface{})
- func SliceCopy(data []interface{}) []interface{}
- func SliceDelete(data []interface{}, index int) (newSlice []interface{})
- func Throw(exception interface{})
- func TryCatch(try func(), catch ...func(exception interface{}))
- type Comparator
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 Dump ¶
func Dump(i ...interface{})
Dump prints variables <i...> to stdout with more manually readable.
func Export ¶
func Export(i ...interface{}) string
Export returns variables <i...> as a string with more manually readable.
func IsEmpty ¶
func IsEmpty(value interface{}) bool
IsEmpty checks given <value> empty or not. It returns false if <value> is: integer(0), bool(false), slice/map(len=0), nil; or else returns true.
func ItemValue ¶
func ItemValue(item interface{}, key interface{}) (value interface{})
ItemValue retrieves and returns its value of which name/attribute specified by <key>. The parameter <item> can be type of map/*map/struct/*struct.
func ListItemValues ¶
func ListItemValues(list interface{}, key interface{}, subKey ...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.
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 MapContains ¶
MapContains checks whether map <data> contains <key>.
func MapContainsPossibleKey ¶
MapContainsPossibleKey checks if the given <key> is contained in given map <data>. It checks the key with or without cases or chars '-'/'_'/'.'/' '.
Note that this function might be of low performance.
func MapCopy ¶
MapCopy does a shallow copy from map <data> to <copy> for most commonly used map type map[string]interface{}.
func MapMergeCopy ¶
MapMergeCopy creates and returns a new map which merges all map from <src>.
func MapPossibleItemByKey ¶
func MapPossibleItemByKey(data map[string]interface{}, key string) (foundKey string, foundValue interface{})
MapPossibleItemByKey tries to find the possible key-value pair for given key with or without cases or chars '-'/'_'/'.'/' '.
Note that this function might be of low performance.
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.
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