...

Package util

import "github.com/Diarkis/diarkis/util"
Overview
Index

Overview ▾

Package util ▷

Util module offers plethora of helper functions to aid your application development.

Data type assertion

Some Diarkis functions extensively use interface{} data type for its flexibility, however, it may lead to type assertion error and causes your server to crash unexpectedly. Util module offers safe type assertion functions for interface{} data type variables.

▶︎ Primitives

Type assertion of an element of a map:

// All numeric assertion also converts float64 to any given numeric type
// For example: if the given interface{} variable is actually a float64,
// GetAsUint will return as an uint etc.
GetAsUint(mapData map[string]interface{}, key string)
GetAsUint8(mapData map[string]interface{}, key string)
GetAsUint16(mapData map[string]interface{}, key string)
GetAsUint32(mapData map[string]interface{}, key string)
GetAsUint64(mapData map[string]interface{}, key string)
GetAsInt(mapData map[string]interface{}, key string)
GetAsInt8(mapData map[string]interface{}, key string)
GetAsInt16(mapData map[string]interface{}, key string)
GetAsInt32(mapData map[string]interface{}, key string)
GetAsInt64(mapData map[string]interface{}, key string)
GetAsFloat32(mapData map[string]interface{}, key string)
GetAsFloat64(mapData map[string]interface{}, key string)

GetAsBool(mapData map[string]interface{}, key string)

▶︎ String

Type assertion of an element of a map:

GetAsString(mapData map[string]interface{}, key string)

▶︎ Byte Array

Type assertion of an element of a map:

// Converts base64 encoded byte array as interface{} as well
GetAsBytes(mapData map[string]interface{}, key string)

▶︎ Arrays

Type assertion of an element of a map:

GetAsStringArray(map[string]interface{}, key string)

// All numeric assertion also converts float64 to any given numeric type
// For example: if the given interface{} variable is actually a float64,
// GetAsUint will return as an uint etc.
GetAsUintArray(map[string]interface{}, key string)
GetAsUint8Array(map[string]interface{}, key string)
GetAsUint16Array(map[string]interface{}, key string)
GetAsUint32Array(map[string]interface{}, key string)
GetAsUint64Array(map[string]interface{}, key string)
GetAsIntArray(map[string]interface{}, key string)
GetAsInt8Array(map[string]interface{}, key string)
GetAsInt16Array(map[string]interface{}, key string)
GetAsInt32Array(map[string]interface{}, key string)
GetAsInt64Array(map[string]interface{}, key string)
GetAsFloat32Array(map[string]interface{}, key string)
GetAsFloat64Array(map[string]interface{}, key string)

GetAsBoolArray(map[string]interface{}, key string)

// Converts base64 encoded byte array as interface{} as well
GetAsBytesArray(map[string]interface{}, key string)

▶︎ Primitives

Type assertion of a variable:

// All numeric assertion also converts float64 to any given numeric type
// For example: if the given interface{} variable is actually a float64,
// GetAsUint will return as an uint etc.
ToUint(data interface{})
ToUint8(data interface{})
ToUint16(data interface{})
ToUint32(data interface{})
ToUint64(data interface{})
ToInt(data interface{})
ToInt8(data interface{})
ToInt16(data interface{})
ToInt32(data interface{})
ToInt64(data interface{})
ToFloat32(data interface{})
ToFloat64(data interface{})

ToBool(data interface{})

▶︎ String

Type assertion of a variable:

ToString(data interface{})

▶︎ Byte Array

Type assertion of a variable:

// Converts base64 encoded byte array as interface{} as well
ToBytes(data interface{})

▶︎ Arrays

Type assertion of a variable:

ToStringArray(data interface{})

// All numeric assertion also converts float64 to any given numeric type
// For example: if the given interface{} variable is actually a float64,
// GetAsUint will return as an uint etc.
ToUintArray(data interface{})
ToUint8Array(data interface{})
ToUint16Array(data interface{})
ToUint32Array(data interface{})
ToUint64Array(data interface{})
ToIntArray(data interface{})
ToInt8Array(data interface{})
ToInt16Array(data interface{})
ToInt32Array(data interface{})
ToInt64Array(data interface{})
ToFloat32Array(data interface{})
ToFloat64Array(data interface{})

ToBoolArraydata interface{})

// Converts base64 encoded byte array as interface{} as well
ToBytesArray(data interface{})

Index ▾

Constants
func AddrToBytes(addr string) ([]byte, error)
func ArrayEqual(d1 interface{}, d2 interface{}) bool
func BytesListToBytes(list [][]byte) []byte
func BytesSliceEqual(v1 [][]byte, v2 [][]byte) bool
func BytesToBytesList(bytes []byte) [][]byte
func CreateAddressID(addr string) (string, error)
func CreateBox(w int, text string, alignment int, isTop, connecting bool) string
func DeleteFromTmp(name string)
func FlattenErrorStackTrace(message string) string
func Float32SliceEqual(v1 []float32, v2 []float32) bool
func Float64SliceEqual(v1 []float64, v2 []float64) bool
func ForEachParallel(list []interface{}, operation func(interface{}, func(error)), done func(error))
func GenShortID() (string, error)
func GetAddressFromAddressID(id string) (string, error)
func GetAsBool(data map[string]interface{}, k string) (bool, bool)
func GetAsBoolArray(data map[string]interface{}, k string) ([]bool, bool)
func GetAsBytes(data map[string]interface{}, k string) ([]byte, bool)
func GetAsBytesArray(data map[string]interface{}, k string) ([][]byte, bool)
func GetAsFloat32(data map[string]interface{}, k string) (float32, bool)
func GetAsFloat32Array(data map[string]interface{}, k string) ([]float32, bool)
func GetAsFloat64(data map[string]interface{}, k string) (float64, bool)
func GetAsFloat64Array(data map[string]interface{}, k string) ([]float64, bool)
func GetAsInt(data map[string]interface{}, k string) (int, bool)
func GetAsInt16(data map[string]interface{}, k string) (int16, bool)
func GetAsInt16Array(data map[string]interface{}, k string) ([]int16, bool)
func GetAsInt32(data map[string]interface{}, k string) (int32, bool)
func GetAsInt32Array(data map[string]interface{}, k string) ([]int32, bool)
func GetAsInt64(data map[string]interface{}, k string) (int64, bool)
func GetAsInt64Array(data map[string]interface{}, k string) ([]int64, bool)
func GetAsInt8(data map[string]interface{}, k string) (int8, bool)
func GetAsInt8Array(data map[string]interface{}, k string) ([]int8, bool)
func GetAsIntArray(data map[string]interface{}, k string) ([]int, bool)
func GetAsString(data map[string]interface{}, k string) (string, bool)
func GetAsStringArray(data map[string]interface{}, k string) ([]string, bool)
func GetAsStringKeyBytesMap(data map[string]interface{}, key string) (map[string][]byte, bool)
func GetAsStringKeyInt64Map(data map[string]interface{}, key string) (map[string]int64, bool)
func GetAsStringKeyIntMap(data map[string]interface{}, key string) (map[string]int, bool)
func GetAsStringKeyInterfaceMap(data map[string]interface{}, key string) (map[string]interface{}, bool)
func GetAsUint(data map[string]interface{}, k string) (uint, bool)
func GetAsUint16(data map[string]interface{}, k string) (uint16, bool)
func GetAsUint16Array(data map[string]interface{}, k string) ([]uint16, bool)
func GetAsUint32(data map[string]interface{}, k string) (uint32, bool)
func GetAsUint32Array(data map[string]interface{}, k string) ([]uint32, bool)
func GetAsUint64(data map[string]interface{}, k string) (uint64, bool)
func GetAsUint64Array(data map[string]interface{}, k string) ([]uint64, bool)
func GetAsUint8(data map[string]interface{}, k string) (uint8, bool)
func GetAsUint8Array(data map[string]interface{}, k string) ([]uint8, bool)
func GetAsUintArray(data map[string]interface{}, k string) ([]uint, bool)
func GetEnv(name string) string
func GetID(nodeAddrList []string) (string, error)
func GetPublicEndPointAWS() (string, error)
func GetPublicEndPointAlibaba() (string, error)
func GetPublicEndPointGCP() (string, error)
func GetPublicEndPointGeneric() (string, error)
func GetPublicEndPointLinode() (string, error)
func GetPublicEndPointMS() (string, error)
func GetPublicEndPointMSLB() (string, error)
func GetPublicEndPointTencent() (string, error)
func IndexOf(array []string, me string) int
func Int16SliceEqual(v1 []int16, v2 []int16) bool
func Int32SliceEqual(v1 []int32, v2 []int32) bool
func Int64SliceEqual(v1 []int64, v2 []int64) bool
func Int8SliceEqual(v1 []int8, v2 []int8) bool
func IntSliceEqual(v1 []int, v2 []int) bool
func InterfaceEqual(d1 interface{}, d2 interface{}) bool
func InterfaceSliceEqual(v1 []interface{}, v2 []interface{}) bool
func IsArray(data interface{}) bool
func IsNullBytes(buf []byte) bool
func IsPrimitiveDataType(v interface{}) bool
func LeadingZero(num int, digit int) string
func NanoSecHex() string
func NanoSecRandHex() string
func NewError(message interface{}, vars ...interface{}) error
func NowMilliseconds() int64
func NowNanoseconds() int64
func NowSeconds() int64
func Parallel(funcs []func(func(error)), done func(error))
func ParseID(id string) (string, []string, error)
func RandomInt(min int, max int) int
func ReadFromTmp(name string) string
func RemoveErrorStackTrace(message string) string
func ReverseArray[T any](array []T) []T
func ReverseBytes(bytes []byte) []byte
func RmSpaces(str string) string
func SetEnv(name string, val string)
func Setup()
func StackError(err error, errs ...error) error
func StrConcat(strlist ...string) string
func ToBool(v interface{}) (bool, bool)
func ToBoolArray(data interface{}) ([]bool, bool)
func ToBytes(v interface{}) ([]byte, bool)
func ToBytesArray(data interface{}) ([][]byte, bool)
func ToFixed(num float64, precision int) string
func ToFloat32(v interface{}) (float32, bool)
func ToFloat32Array(data interface{}) ([]float32, bool)
func ToFloat64(v interface{}) (float64, bool)
func ToFloat64Array(data interface{}) ([]float64, bool)
func ToInt(v interface{}) (int, bool)
func ToInt16(v interface{}) (int16, bool)
func ToInt16Array(data interface{}) ([]int16, bool)
func ToInt32(v interface{}) (int32, bool)
func ToInt32Array(data interface{}) ([]int32, bool)
func ToInt64(v interface{}) (int64, bool)
func ToInt64Array(data interface{}) ([]int64, bool)
func ToInt8(v interface{}) (int8, bool)
func ToInt8Array(data interface{}) ([]int8, bool)
func ToIntArray(data interface{}) ([]int, bool)
func ToString(v interface{}) (string, bool)
func ToStringArray(data interface{}) ([]string, bool)
func ToStringKeyBytesMap(d interface{}) (map[string][]byte, bool)
func ToStringKeyInt64Map(d interface{}) (map[string]int64, bool)
func ToStringKeyIntMap(d interface{}) (map[string]int, bool)
func ToStringKeyInterfaceMap(d interface{}) (map[string]interface{}, bool)
func ToUint(v interface{}) (uint, bool)
func ToUint16(v interface{}) (uint16, bool)
func ToUint16Array(data interface{}) ([]uint16, bool)
func ToUint32(v interface{}) (uint32, bool)
func ToUint32Array(data interface{}) ([]uint32, bool)
func ToUint64(v interface{}) (uint64, bool)
func ToUint64Array(data interface{}) ([]uint64, bool)
func ToUint8(v interface{}) (uint8, bool)
func ToUint8Array(data interface{}) ([]uint8, bool)
func ToUintArray(data interface{}) ([]uint, bool)
func Uint16SliceEqual(v1 []uint16, v2 []uint16) bool
func Uint32SliceEqual(v1 []uint32, v2 []uint32) bool
func Uint64SliceEqual(v1 []uint64, v2 []uint64) bool
func Uint8SliceEqual(v1 []uint8, v2 []uint8) bool
func UintSliceEqual(v1 []uint, v2 []uint) bool
func Waterfall(funcs []func(func(error)), done func(error))
func WriteToTmp(name string, val string)
func ZuluTimeFormat(now time.Time) string
type Await
    func Async(taskNum int) *Await
type Parcel
    func NewParcel() *Parcel
    func (p *Parcel) Add(key string, value interface{}) bool
    func (p *Parcel) Export() map[string]interface{}
    func (p *Parcel) Remove(key string) bool
type StringArray
    func NewStringArray() *StringArray
    func NewStringArrayFromExportedData(data string) *StringArray
    func (sa *StringArray) Clear()
    func (sa *StringArray) Delete(value string) bool
    func (sa *StringArray) Export() string
    func (sa *StringArray) GetAt(index int) string
    func (sa *StringArray) GetIndex(value string) int
    func (sa *StringArray) Length() int
    func (sa *StringArray) Pop() string
    func (sa *StringArray) Push(value string)
type StringMap
    func NewStringMap() *StringMap
    func NewStringMapFromExportedData(data string) *StringMap
    func (sm *StringMap) Clear()
    func (sm *StringMap) Delete(key string) bool
    func (sm *StringMap) Export() string
    func (sm *StringMap) Get(key string) string
    func (sm *StringMap) Length() int
    func (sm *StringMap) Set(key string, value string)

Constants

CmdBroadcastGroup The command ID of built-in broadcast group command

const CmdBroadcastGroup uint16 = 113

CmdBroadcastRoom The command ID of built-in broadcast to room command

const CmdBroadcastRoom uint16 = 103

CmdBuiltInUtilClientKey Command used for clientKey if required

const CmdBuiltInUtilClientKey uint16 = 4

CmdBuiltInUtilFin Command used for WebSocket server to close the server socket when received

const CmdBuiltInUtilFin uint16 = 0

CmdBuiltInUtilKeepAlive Command used for heartbeat of TCP and echo of RUDP

const CmdBuiltInUtilKeepAlive uint16 = 1

CmdBuiltInUtilPing Command used for ping of UDP

const CmdBuiltInUtilPing uint16 = 3

CmdBuiltInUtilReconn Command used for client reconnect

const CmdBuiltInUtilReconn uint16 = 2

CmdBuiltInUtilReconnWithType Command used for client reconnect with specific server type

const CmdBuiltInUtilReconnWithType uint16 = 5

CmdBuiltInUtilVer Command version strictly used by diarkis internal

const CmdBuiltInUtilVer uint8 = 0

CmdBuiltInVer All built-in commands' version

const CmdBuiltInVer uint8 = 1

CmdCancelReserveRoom The command ID of built-in message to room support command

const CmdCancelReserveRoom uint16 = 118

CmdCreateGroup The command ID of built-in create group command

const CmdCreateGroup uint16 = 110

CmdCreateRoom The command ID of built-in create room command

const CmdCreateRoom uint16 = 100

CmdDMConn The command ID for built-in DM call connect This command is deprecated because the connect event of the DirectMessage is no longer used.

const CmdDMConn uint16 = 702

CmdDMDisconn The command ID for built-in DM call disconnect

const CmdDMDisconn uint16 = 700

CmdDMSend The command ID for built-in DM call send

const CmdDMSend uint16 = 701

CmdDebugOffline debug command

const CmdDebugOffline uint16 = 902

CmdDebugOnline debug command

const CmdDebugOnline uint16 = 900

CmdDebugRoomDump debug command

const CmdDebugRoomDump uint16 = 904

CmdDebugTaken debug command

const CmdDebugTaken uint16 = 901

CmdDebugTerminate debug command

const CmdDebugTerminate uint16 = 903

CmdDebugUserDump debug command

const CmdDebugUserDump uint16 = 905

CmdFieldDisappear The command ID for built-in field command

const CmdFieldDisappear uint16 = 123

CmdFieldJoin The command IF of built-in field command

const CmdFieldJoin uint16 = 120

CmdFieldLeave The command ID for built-in field command

const CmdFieldLeave uint16 = 124

CmdFieldSync The command ID for build-in field command

const CmdFieldSync uint16 = 121

CmdFindRooms The command ID of built-in message to room support command

const CmdFindRooms uint16 = 116

CmdGetNumOfRoomMembers The command ID of built-in room member number

const CmdGetNumOfRoomMembers uint16 = 13

CmdGetRoomMemberIDs The command ID of built-in member user IDs sync

const CmdGetRoomMemberIDs uint16 = 11

CmdGetRoomOwnerID The command ID of built-in get command

const CmdGetRoomOwnerID uint16 = 109

CmdGetRoomProp The command ID of built-in property get command

const CmdGetRoomProp uint16 = 108

CmdIncrRoomProp The command ID of built-in increment room prop

const CmdIncrRoomProp uint16 = 10

CmdJoinGroup The command ID of built-in join group command

const CmdJoinGroup uint16 = 111

CmdJoinRoom The command ID of built-in join room command

const CmdJoinRoom uint16 = 101

CmdLeaveGroup The command ID of built-in leave group command

const CmdLeaveGroup uint16 = 112

CmdLeaveRoom The command ID of built-in leave room command

const CmdLeaveRoom uint16 = 102

CmdMMBackfill The command ID for built-in MatchMaker

const CmdMMBackfill uint16 = 211

CmdMMClaim The command ID for built-in MatchMaker

const CmdMMClaim uint16 = 205

CmdMMCommit The command ID for built-in MatchMaker

const CmdMMCommit uint16 = 215

CmdMMComplete The command ID for built-in MatchMaker

const CmdMMComplete uint16 = 206

CmdMMCompleteCommit The command ID for built-in MatchMaker

const CmdMMCompleteCommit uint16 = 216

CmdMMDisbandTeam The command ID for built-in MatchMaker

const CmdMMDisbandTeam uint16 = 212

CmdMMHostChange The command ID for built-in MatchMaker

const CmdMMHostChange uint16 = 221

CmdMMKick The command ID for built-in MatchMaker

const CmdMMKick uint16 = 217

CmdMMLeave The command ID for built-in MatchMaker

const CmdMMLeave uint16 = 203

CmdMMNewTeam The command ID for built-in MatchMaker

const CmdMMNewTeam uint16 = 209

CmdMMP2P The command ID for built-in MatchMaker

const CmdMMP2P uint16 = 208

CmdMMRemove The command ID for built-in MatchMaker

const CmdMMRemove uint16 = 202

CmdMMSearch The command ID for built-in MatchMaker

const CmdMMSearch uint16 = 201

CmdMMSearchList The command ID for built-in MatchMaker

const CmdMMSearchList uint16 = 207

CmdMMSync The command ID for built-in MatchMaker

const CmdMMSync uint16 = 204

CmdMMTeamComplete The command ID for built-in MatchMaker

const CmdMMTeamComplete uint16 = 213

CmdMMTeamSearch The command ID for built-in MatchMaker

const CmdMMTeamSearch uint16 = 214

CmdMMTeamSync The command ID for built-in MatchMaker

const CmdMMTeamSync uint16 = 210

CmdMMTicket The command ID for built-in MatchMaker

const CmdMMTicket uint16 = 218

CmdMMTicketBroadcast The command ID for built-in MatchMaker

const CmdMMTicketBroadcast uint16 = 224

CmdMMTicketCancel The command ID for built-in MatchMaker

const CmdMMTicketCancel uint16 = 222

CmdMMTicketComplete The command ID for built-in MatchMaker

const CmdMMTicketComplete uint16 = 220

CmdMMTicketErr The command ID for built-in MatchMaker

const CmdMMTicketErr uint16 = 219

CmdMMTicketLeave The command ID for built-in MatchMaker

const CmdMMTicketLeave uint16 = 225

CmdMMTicketMatch The command ID for built-in MatchMaker

const CmdMMTicketMatch uint16 = 223

CmdMMWait The command ID for built-in MatchMaker

const CmdMMWait uint16 = 200

CmdMessageRoom The command ID of built-in message to room command

const CmdMessageRoom uint16 = 104

CmdMigrateRoom The command ID of built-in room migration

const CmdMigrateRoom uint16 = 12

CmdMigratedRoom event that is invoked when a member of a room finishes room migration

const CmdMigratedRoom uint16 = 20

CmdNotification The command ID for built-in server notification

const CmdNotification uint16 = 400

CmdP2PCheckNATType The command ID for built-in P2P to check NAT type

const CmdP2PCheckNATType uint16 = 305

CmdP2PInit The command ID for built-in P2P

const CmdP2PInit uint16 = 127

CmdP2PNotifyPingTryDone The command ID for built-in P2P to notify the server that hole punching is done

const CmdP2PNotifyPingTryDone uint16 = 304

CmdP2PRelay The command ID for built-in P2P

const CmdP2PRelay uint16 = 302

CmdP2PRequestPingTry The command ID for built-in P2P to let the server request hole punching to the passed address

const CmdP2PRequestPingTry uint16 = 303

CmdP2PSuccess The command ID for built-in report for P2P success

const CmdP2PSuccess uint16 = 301

CmdRandCreateRoom The command ID of built-in create room command for random join

const CmdRandCreateRoom uint16 = 105

CmdRandJoinGroup The command ID of built-in message to room support command

const CmdRandJoinGroup uint16 = 114

CmdRandJoinRoom The command ID of built-in join room for random join

const CmdRandJoinRoom uint16 = 106

CmdRegisterRoom The command ID of built-in message to room support command

const CmdRegisterRoom uint16 = 115

CmdReserveRoom The command ID of built-in message to room support command

const CmdReserveRoom uint16 = 117

CmdRoomChatLog The command ID for built-in room chat log

const CmdRoomChatLog uint16 = 126

CmdRoomChatSync The command ID for built-in room chat sync

const CmdRoomChatSync uint16 = 125

CmdRoomObjUpdate The command ID for built-in room object update

const CmdRoomObjUpdate uint16 = 129

CmdRoomOwnerChange The command ID of built-in room owner change

const CmdRoomOwnerChange uint16 = 14

CmdRoomPropertySync The command ID for built-in room property sync

const CmdRoomPropertySync uint16 = 130

CmdRoomRelay The command ID of built-in room relay

const CmdRoomRelay uint16 = 18

CmdRoomRelayProfile The command ID of built-in room relay profile

const CmdRoomRelayProfile uint16 = 19

CmdRoomRelayTo The build-in command ID for room relayTo

const CmdRoomRelayTo uint16 = 23

CmdRoomRelayToProfile The build-in command ID for room relayToProfile

const CmdRoomRelayToProfile uint16 = 24

CmdRoomStateIncr The command ID of built-in room state update by increment

const CmdRoomStateIncr uint16 = 16

CmdRoomStateSync The command ID of built-in room state sync from the server

const CmdRoomStateSync uint16 = 17

CmdRoomStateUpdate The command ID of built-in room state update

const CmdRoomStateUpdate uint16 = 15

CmdSessionBroadcast The command ID for built-in Session Broadcast

const CmdSessionBroadcast uint16 = 800

CmdSessionCreate The command ID for built-in Session Create

const CmdSessionCreate uint16 = 801

CmdSessionGetSessionInfoBySessionID The command ID for built-in get Session info by session ID

const CmdSessionGetSessionInfoBySessionID uint16 = 809

CmdSessionGetSessionInfoBySessionType The command ID for built-in get Session info by session type

const CmdSessionGetSessionInfoBySessionType uint16 = 808

CmdSessionInvite The command ID for built-in Session Invite

const CmdSessionInvite uint16 = 802

CmdSessionJoin The command ID for built-in Session Join

const CmdSessionJoin uint16 = 804

CmdSessionKick The command ID for built-in Kick out users from Session

const CmdSessionKick uint16 = 806

CmdSessionLeave The command ID for built-in Session Leave

const CmdSessionLeave uint16 = 805

CmdSessionMessageTo The command ID for built-in Kick out users from Session

const CmdSessionMessageTo uint16 = 807

CmdUpdateRoomProp The command ID of built-in property update command

const CmdUpdateRoomProp uint16 = 107

MeshDMCallConn Mesh network command ID

const MeshDMCallConn uint16 = 100

MeshDMCallDisconn Mesh network command ID

const MeshDMCallDisconn uint16 = 102

MeshDMCallSend Mesh network command ID

const MeshDMCallSend uint16 = 101

MeshDiveDelete Mesh network command ID

const MeshDiveDelete uint16 = 620

MeshDiveGet Mesh network command ID

const MeshDiveGet uint16 = 610

MeshDiveIncrBy Mesh network command ID

const MeshDiveIncrBy uint16 = 624

MeshDiveLPop Mesh network command ID

const MeshDiveLPop uint16 = 612

MeshDiveLPush Mesh network command ID

const MeshDiveLPush uint16 = 602

MeshDiveLRange Mesh network command ID

const MeshDiveLRange uint16 = 611

MeshDiveMigrate Mesh network command ID

const MeshDiveMigrate uint16 = 640

MeshDiveRPop Mesh network command ID

const MeshDiveRPop uint16 = 613

MeshDiveRPush Mesh network command ID

const MeshDiveRPush uint16 = 603

MeshDiveSet Mesh network command ID

const MeshDiveSet uint16 = 600

MeshDiveSetIfNotExists Mesh network command ID

const MeshDiveSetIfNotExists uint16 = 601

MeshFieldSyncPropagation Mesh network command ID

const MeshFieldSyncPropagation uint16 = 51

MeshFieldSyncUpdate Mesh network command ID

const MeshFieldSyncUpdate uint16 = 50

MeshGetHolePunchingAddress Mesh network command ID

const MeshGetHolePunchingAddress = 91

MeshGetRoomData Mesh network command ID

const MeshGetRoomData uint16 = 16

MeshGetRoomProperties mesh network command ID

const MeshGetRoomProperties uint16 = 18

MeshGetRoomProperty mesh network command ID

const MeshGetRoomProperty uint16 = 17

MeshGroupBroadcastSync Mesh network command ID

const MeshGroupBroadcastSync uint16 = 22

MeshGroupJoin Mesh network command ID

const MeshGroupJoin uint16 = 21

MeshGroupSync Mesh network command ID

const MeshGroupSync uint16 = 23

MeshHealthCheck Mesh network command ID

const MeshHealthCheck uint16 = 1020

MeshMARSDel Mesh network command ID

const MeshMARSDel uint16 = 1001

MeshMARSSScan Mesh network command ID

const MeshMARSSScan uint16 = 1000

MeshMARSShow mesh command to show lists of nodes in the clusters

const MeshMARSShow uint16 = 1002

MeshMatchMakingAdd Mesh network command ID

const MeshMatchMakingAdd uint16 = 40

MeshMatchMakingSearch Mesh network command ID

const MeshMatchMakingSearch uint16 = 41

MeshMatchMakingUpdateRoom Mesh network command ID

const MeshMatchMakingUpdateRoom uint16 = 39

MeshMatchingBroadcastPropagateRoom Mesh network command ID

const MeshMatchingBroadcastPropagateRoom uint16 = 47

MeshMatchingBroadcastRoom Mesh network command ID

const MeshMatchingBroadcastRoom uint16 = 46

MeshMatchingCancel Mesh network command ID

const MeshMatchingCancel uint16 = 400

MeshMatchingJoinRoom Mesh network command ID

const MeshMatchingJoinRoom uint16 = 44

MeshMatchingLeaveRoom Mesh network command ID

const MeshMatchingLeaveRoom uint16 = 45

MeshMatchingMembersRoom Mesh network command ID

const MeshMatchingMembersRoom uint16 = 48

MeshMatchingMoveRoom Mesh network command ID

const MeshMatchingMoveRoom uint16 = 43

MeshMatchingRemove Mesh network command ID

const MeshMatchingRemove uint16 = 42

MeshMatchingTimeout Mesh network command ID

const MeshMatchingTimeout uint16 = 401

MeshMatchingUpdateUserDataRoom Mesh network command ID

const MeshMatchingUpdateUserDataRoom uint16 = 49

MeshMigrate Mesh network command ID

const MeshMigrate uint16 = 80

MeshNotify Mesh network command ID

const MeshNotify uint16 = 200

MeshRequestHolePunching Mesh network command ID

const MeshRequestHolePunching = 90

MeshRoomBackupDel Mesh network command ID

const MeshRoomBackupDel uint16 = 14

MeshRoomBackupExtend Mesh network command ID

const MeshRoomBackupExtend uint16 = 12

MeshRoomBackupNew Mesh network command ID

const MeshRoomBackupNew uint16 = 11

MeshRoomBackupState Mesh network command ID

const MeshRoomBackupState uint16 = 24

MeshRoomBackupUpdate Mesh network command ID

const MeshRoomBackupUpdate uint16 = 13

MeshRoomCancelReserve mesh network command ID

const MeshRoomCancelReserve uint16 = 19

MeshRoomJoin Mesh network command ID

const MeshRoomJoin uint16 = 10

MeshRoomMigrate Mesh network command ID

const MeshRoomMigrate uint16 = 15

MeshSendPM Mesh network command ID

const MeshSendPM uint16 = 60

MeshSessionBroadcastSession Mesh network command ID

const MeshSessionBroadcastSession uint16 = 302

MeshSessionCreate Mesh network command ID for sending session data from HTTP to TCP/UDP

const MeshSessionCreate uint16 = 20

MeshSessionFindToKick Mesh network command ID

const MeshSessionFindToKick uint16 = 306

MeshSessionGetMemberIDs Mesh network command ID

const MeshSessionGetMemberIDs uint16 = 314

MeshSessionGetMemberSIDs Mesh network command ID

const MeshSessionGetMemberSIDs uint16 = 315

MeshSessionGetProperties Mesh network command ID

const MeshSessionGetProperties uint16 = 313

MeshSessionGetProperty Mesh network command ID

const MeshSessionGetProperty uint16 = 312

MeshSessionGetSessionInfo Mesh network command ID

const MeshSessionGetSessionInfo uint16 = 317

MeshSessionGetUserDataSession Mesh network command ID

const MeshSessionGetUserDataSession uint16 = 316

MeshSessionIsOwner Mesh network command ID

const MeshSessionIsOwner uint16 = 309

MeshSessionJoinSession Mesh network command ID

const MeshSessionJoinSession uint16 = 300

MeshSessionKick Mesh network command ID

const MeshSessionKick uint16 = 307

MeshSessionLeaveSession Mesh network command ID

const MeshSessionLeaveSession uint16 = 301

MeshSessionPropagateMessage Mesh network command ID

const MeshSessionPropagateMessage uint16 = 303

MeshSessionSetProperties Mesh network command ID

const MeshSessionSetProperties uint16 = 311

MeshSessionSetProperty Mesh network command ID

const MeshSessionSetProperty uint16 = 310

MeshSessionUpdateSession Mesh network command ID

const MeshSessionUpdateSession uint16 = 304

MeshSessionUpdateUserDataSession Mesh network command ID

const MeshSessionUpdateUserDataSession uint16 = 305

MeshStatusOffline Mesh network node status offline value

const MeshStatusOffline = 2

MeshStatusOnline Mesh network node status online value

const MeshStatusOnline = 1

MeshStatusTaken Mesh network node status taken value

const MeshStatusTaken = 3

MeshSubBJoin Mesh network command ID

const MeshSubBJoin uint16 = 70

SharedDataLimitLength manages the maximum number of shared data entry.

[NOTE] SharedData is shared and updated by any node server in the Diarkis cluster.

const SharedDataLimitLength = 10

func AddrToBytes

func AddrToBytes(addr string) ([]byte, error)

AddrToBytes Converts address (address:port) string to byte array

func ArrayEqual

func ArrayEqual(d1 interface{}, d2 interface{}) bool

ArrayEqual returns a true if the given interface{} share the same values as arrays (slices).

Valid data types for the comparison:

[]uint8
[]uint16
[]uint32
[]uint64
[]int
[]int8
[]int16
[]int32
[]int64
[]int
[]float32
[]float64
[][]byte

func BytesListToBytes

func BytesListToBytes(list [][]byte) []byte

BytesListToBytes converts an array of []byte to a byte array.

[IMPORTANT] each byte array in the list must NOT exceed the size of 255 bytes

Returned byte array format:

Shown below is a single data set and it repeats for as long as the given list.

+-------------+---------------+-----+
| size header |     bytes     | ... |
+-------------+---------------+-----+
|    1 byte   | variable size | ... |
+-------------+---------------+-----+

func BytesSliceEqual

func BytesSliceEqual(v1 [][]byte, v2 [][]byte) bool

BytesSliceEqual compares two arrays of byte array.

Returns true if the two arrays' elements contain the same values.

func BytesToBytesList

func BytesToBytesList(bytes []byte) [][]byte

BytesToBytesList converts an byte array to a list of byte array.

Input byte array must be the output byte array of BytesListToBytes.

func CreateAddressID

func CreateAddressID(addr string) (string, error)

CreateAddressID returns a unique string ID made of UUID v4 and encoded address given. The length of the returned address ID is always 52.

func CreateBox

func CreateBox(w int, text string, alignment int, isTop, connecting bool) string

CreateBox creates a box

func DeleteFromTmp

func DeleteFromTmp(name string)

DeleteFromTmp removes a file under /tmp/ - The file must have a prefix of "DIARKIS_"

func FlattenErrorStackTrace

func FlattenErrorStackTrace(message string) string

FlattenErrorStackTrace replaces error stack traces' line breaks and convert them to a tab.

func Float32SliceEqual

func Float32SliceEqual(v1 []float32, v2 []float32) bool

Float32SliceEqual compares two slices and returns true if all the elements in the arrays match.

func Float64SliceEqual

func Float64SliceEqual(v1 []float64, v2 []float64) bool

Float64SliceEqual compares two slices and returns true if all the elements in the arrays match.

func ForEachParallel

func ForEachParallel(list []interface{}, operation func(interface{}, func(error)), done func(error))

ForEachParallel executes the given operation function on each item in the list in parallel and calls done when finished

func GenShortID

func GenShortID() (string, error)

GenShortID returns a randomly generated HEX encoded ID as a string (8 characters long). Does NOT guarantee uniqueness like UUID v4.

func GetAddressFromAddressID

func GetAddressFromAddressID(id string) (string, error)

GetAddressFromAddressID returns encoded address as a string from an address ID created by CreateAddressID.

func GetAsBool

func GetAsBool(data map[string]interface{}, k string) (bool, bool)

GetAsBool returns a value of the given map by its key as a bool.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be true, if the value is invalid.

[NOTE] Uses mutex lock internally.

func GetAsBoolArray

func GetAsBoolArray(data map[string]interface{}, k string) ([]bool, bool)

GetAsBoolArray returns a value of the given map by its key as an array of bool.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be false, if the value data type is not invalid.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.

[NOTE]      Uses mutex lock internally.

func GetAsBytes

func GetAsBytes(data map[string]interface{}, k string) ([]byte, bool)

GetAsBytes returns a value of the given map by its key as a string.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be true, if the value is invalid.
[IMPORTANT] If the value held is a base64 encoded string, it will be returned as a byte array as a valid value.

[NOTE] Uses mutex lock internally.

func GetAsBytesArray

func GetAsBytesArray(data map[string]interface{}, k string) ([][]byte, bool)

GetAsBytesArray returns a value of the given map by its key as an array of bytes.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be false, if the value data type is not invalid.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.

[NOTE]      Uses mutex lock internally.

func GetAsFloat32

func GetAsFloat32(data map[string]interface{}, k string) (float32, bool)

GetAsFloat32 returns a value of the given map by its key as a float32.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be true, if the value is invalid.
[IMPORTANT] If the held value is float64, it will be converted to the correct type and returned as a valid value.

[NOTE] Uses mutex lock internally.

func GetAsFloat32Array

func GetAsFloat32Array(data map[string]interface{}, k string) ([]float32, bool)

GetAsFloat32Array returns a value of the given map by its key as an array of float32.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be false, if the value data type is not invalid.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.
[IMPORTANT] If one or more elements in the array are to be float64,
            it is an exception that will be auto-converted to the specified numerical data type
            and the second return value will be true.

[NOTE]      Uses mutex lock internally.

func GetAsFloat64

func GetAsFloat64(data map[string]interface{}, k string) (float64, bool)

GetAsFloat64 returns a value of the given map by its key as a float64.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be true, if the value is invalid.
[IMPORTANT] If the held value is float64, it will be converted to the correct type and returned as a valid value.

[NOTE] Uses mutex lock internally.

func GetAsFloat64Array

func GetAsFloat64Array(data map[string]interface{}, k string) ([]float64, bool)

GetAsFloat64Array returns a value of the given map by its key as an array of float64.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be false, if the value data type is not invalid.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.

[NOTE]      Uses mutex lock internally.

func GetAsInt

func GetAsInt(data map[string]interface{}, k string) (int, bool)

GetAsInt returns a value of the given map by its key as a int.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be true, if the value is invalid.
[IMPORTANT] If the held value is float64, it will be converted to the correct type and returned as a valid value.

[NOTE] Uses mutex lock internally.

func GetAsInt16

func GetAsInt16(data map[string]interface{}, k string) (int16, bool)

GetAsInt16 returns a value of the given map by its key as a int16.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be true, if the value is invalid.
[IMPORTANT] If the held value is float64, it will be converted to the correct type and returned as a valid value.

[NOTE] Uses mutex lock internally.

func GetAsInt16Array

func GetAsInt16Array(data map[string]interface{}, k string) ([]int16, bool)

GetAsInt16Array returns a value of the given map by its key as an array of int16.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be false, if the value data type is not invalid.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.
[IMPORTANT] If one or more elements in the array are to be float64,
            it is an exception that will be auto-converted to the specified numerical data type
            and the second return value will be true.

[NOTE]      Uses mutex lock internally.

func GetAsInt32

func GetAsInt32(data map[string]interface{}, k string) (int32, bool)

GetAsInt32 returns a value of the given map by its key as a int32.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be true, if the value is invalid.
[IMPORTANT] If the held value is float64, it will be converted to the correct type and returned as a valid value.

[NOTE] Uses mutex lock internally.

func GetAsInt32Array

func GetAsInt32Array(data map[string]interface{}, k string) ([]int32, bool)

GetAsInt32Array returns a value of the given map by its key as an array of int32.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be false, if the value data type is not invalid.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.
[IMPORTANT] If one or more elements in the array are to be float64,
            it is an exception that will be auto-converted to the specified numerical data type
            and the second return value will be true.

[NOTE]      Uses mutex lock internally.

func GetAsInt64

func GetAsInt64(data map[string]interface{}, k string) (int64, bool)

GetAsInt64 returns a value of the given map by its key as a int64.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be true, if the value is invalid.
[IMPORTANT] If the held value is float64, it will be converted to the correct type and returned as a valid value.

[NOTE] Uses mutex lock internally.

func GetAsInt64Array

func GetAsInt64Array(data map[string]interface{}, k string) ([]int64, bool)

GetAsInt64Array returns a value of the given map by its key as an array of int64.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be false, if the value data type is not invalid.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.
[IMPORTANT] If one or more elements in the array are to be float64,
            it is an exception that will be auto-converted to the specified numerical data type
            and the second return value will be true.

[NOTE]      Uses mutex lock internally.

func GetAsInt8

func GetAsInt8(data map[string]interface{}, k string) (int8, bool)

GetAsInt8 returns a value of the given map by its key as a int8.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be true, if the value is invalid.
[IMPORTANT] If the held value is float64, it will be converted to the correct type and returned as a valid value.

[NOTE] Uses mutex lock internally.

func GetAsInt8Array

func GetAsInt8Array(data map[string]interface{}, k string) ([]int8, bool)

GetAsInt8Array returns a value of the given map by its key as an array of int8.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be false, if the value data type is not invalid.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.
[IMPORTANT] If one or more elements in the array are to be float64,
            it is an exception that will be auto-converted to the specified numerical data type
            and the second return value will be true.

[NOTE]      Uses mutex lock internally.

func GetAsIntArray

func GetAsIntArray(data map[string]interface{}, k string) ([]int, bool)

GetAsIntArray returns a value of the given map by its key as an array of int.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be false, if the value data type is not invalid.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.
[IMPORTANT] If one or more elements in the array are to be float64,
            it is an exception that will be auto-converted to the specified numerical data type
            and the second return value will be true.

[NOTE]      Uses mutex lock internally.

func GetAsString

func GetAsString(data map[string]interface{}, k string) (string, bool)

GetAsString returns a value of the given map by its key as a string.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be true, if the value is invalid.

[NOTE] Uses mutex lock internally.

func GetAsStringArray

func GetAsStringArray(data map[string]interface{}, k string) ([]string, bool)

GetAsStringArray returns a value of the given map by its key as an array of string.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be false, if the value data type is not invalid.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.

[NOTE]      Uses mutex lock internally.

func GetAsStringKeyBytesMap

func GetAsStringKeyBytesMap(data map[string]interface{}, key string) (map[string][]byte, bool)

GetAsStringKeyBytesMap returns a map with string keys and byte array values. from a given map[string]interface{}. The second returned value indicates if the data is valid or not.

func GetAsStringKeyInt64Map

func GetAsStringKeyInt64Map(data map[string]interface{}, key string) (map[string]int64, bool)

GetAsStringKeyInt64Map returns a map with string keys and int64 values. from a given map[string]interface{}. The second returned value indicates if the data is valid or not.

func GetAsStringKeyIntMap

func GetAsStringKeyIntMap(data map[string]interface{}, key string) (map[string]int, bool)

GetAsStringKeyIntMap returns a map with string keys and int values from a given map[string]interface{}. The second returned value indicates if the data is valid or not.

func GetAsStringKeyInterfaceMap

func GetAsStringKeyInterfaceMap(data map[string]interface{}, key string) (map[string]interface{}, bool)

GetAsStringKeyInterfaceMap returns a map with string keys and interface values from a given map[string]interface{}. The second returned value indicates if the data is valid or not.

func GetAsUint

func GetAsUint(data map[string]interface{}, k string) (uint, bool)

GetAsUint returns a value of the given map by its key as a uint.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be true, if the value is invalid.
[IMPORTANT] If the held value is float64, it will be converted to the correct type and returned as a valid value.

[NOTE] Uses mutex lock internally.

func GetAsUint16

func GetAsUint16(data map[string]interface{}, k string) (uint16, bool)

GetAsUint16 returns a value of the given map by its key as a uint16.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be true, if the value is invalid.
[IMPORTANT] If the held value is float64, it will be converted to the correct type and returned as a valid value.

[NOTE] Uses mutex lock internally.

func GetAsUint16Array

func GetAsUint16Array(data map[string]interface{}, k string) ([]uint16, bool)

GetAsUint16Array returns a value of the given map by its key as an array of uint16.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be false, if the value data type is not invalid.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.
[IMPORTANT] If one or more elements in the array are to be float64,
            it is an exception that will be auto-converted to the specified numerical data type
            and the second return value will be true.

[NOTE]      Uses mutex lock internally.

func GetAsUint32

func GetAsUint32(data map[string]interface{}, k string) (uint32, bool)

GetAsUint32 returns a value of the given map by its key as a uint32.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be true, if the value is invalid.
[IMPORTANT] If the held value is float64, it will be converted to the correct type and returned as a valid value.

[NOTE] Uses mutex lock internally.

func GetAsUint32Array

func GetAsUint32Array(data map[string]interface{}, k string) ([]uint32, bool)

GetAsUint32Array returns a value of the given map by its key as an array of uint32.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be false, if the value data type is not invalid.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.
[IMPORTANT] If one or more elements in the array are to be float64,
            it is an exception that will be auto-converted to the specified numerical data type
            and the second return value will be true.

[NOTE]      Uses mutex lock internally.

func GetAsUint64

func GetAsUint64(data map[string]interface{}, k string) (uint64, bool)

GetAsUint64 returns a value of the given map by its key as a uint32.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be true, if the value is invalid.
[IMPORTANT] If the held value is float64, it will be converted to the correct type and returned as a valid value.

[NOTE] Uses mutex lock internally.

func GetAsUint64Array

func GetAsUint64Array(data map[string]interface{}, k string) ([]uint64, bool)

GetAsUint64Array returns a value of the given map by its key as an array of uint64.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be false, if the value data type is not invalid.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.
[IMPORTANT] If one or more elements in the array are to be float64,
            it is an exception that will be auto-converted to the specified numerical data type
            and the second return value will be true.

[NOTE]      Uses mutex lock internally.

func GetAsUint8

func GetAsUint8(data map[string]interface{}, k string) (uint8, bool)

GetAsUint8 returns a value of the given map by its key as a uint8.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be true, if the value is invalid.
[IMPORTANT] If the held value is float64, it will be converted to the correct type and returned as a valid value.

[NOTE] Uses mutex lock internally.

func GetAsUint8Array

func GetAsUint8Array(data map[string]interface{}, k string) ([]uint8, bool)

GetAsUint8Array returns a value of the given map by its key as an array of uint8.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be false, if the value data type is not invalid.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.
[IMPORTANT] If one or more elements in the array are to be float64,
            it is an exception that will be auto-converted to the specified numerical data type
            and the second return value will be true.

[NOTE]      Uses mutex lock internally.

func GetAsUintArray

func GetAsUintArray(data map[string]interface{}, k string) ([]uint, bool)

GetAsUintArray returns a value of the given map by its key as an array of uint.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be false, if the value data type is not invalid.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.
[IMPORTANT] If one or more elements in the array are to be float64,
            it is an exception that will be auto-converted to the specified numerical data type
            and the second return value will be true.

[NOTE]      Uses mutex lock internally.

func GetEnv

func GetEnv(name string) string

GetEnv returns a value of an environment variable w/ the given name all env name must have a prefix of "DIARKIS_"

func GetID

func GetID(nodeAddrList []string) (string, error)

GetID Returns a unique ID with mesh node address encoded in it - Length of the returned ID is 52

func GetPublicEndPointAWS

func GetPublicEndPointAWS() (string, error)

GetPublicEndPointAWS returns the public endpoint hostname in Google Cloud Computing When diarkis process is ready (diarkis.OnReady(callback)), you set this value to server.SetPublicEndPoint(endpoint)

func GetPublicEndPointAlibaba

func GetPublicEndPointAlibaba() (string, error)

GetPublicEndPointAlibaba returns the public endpoint hostname in Alibaba Cloud When diarkis process is ready (diarkis.OnReady(callback)), you set this value to server.SetPublicEndPoint(endpoint)

func GetPublicEndPointGCP

func GetPublicEndPointGCP() (string, error)

GetPublicEndPointGCP returns the public endpoint hostname in Google Cloud Computing When diarkis process is ready (diarkis.OnReady(callback)), you set this value to server.SetPublicEndPoint(endpoint)

func GetPublicEndPointGeneric

func GetPublicEndPointGeneric() (string, error)

GetPublicEndPointGeneric [INTERNAL USE ONLY] returns the public endpoint hostname by curling ifconfig.io When diarkis process is ready (diarkis.OnReady(callback)), you set this value to server.SetPublicEndPoint(endpoint)

func GetPublicEndPointLinode

func GetPublicEndPointLinode() (string, error)

GetPublicEndPointLinode returns the public endpoint hostname in Linode When diarkis process is ready (diarkis.OnReady(callback)), you set this value to server.SetPublicEndPoint(endpoint)

func GetPublicEndPointMS

func GetPublicEndPointMS() (string, error)

GetPublicEndPointMS returns the public endpoint address in MS Azure Cloud When diarkis process is ready (diarkis.OnReady(callback)), you set this value to server.SetPublicEndPoint(endpoint)

func GetPublicEndPointMSLB

func GetPublicEndPointMSLB() (string, error)

GetPublicEndPointMSLB returns the public endpoint address in MS Azure Cloud with Loadbalancer in front When diarkis process is ready (diarkis.OnReady(callback)), you set this value to server.SetPublicEndPoint(endpoint)

func GetPublicEndPointTencent

func GetPublicEndPointTencent() (string, error)

GetPublicEndPointTencent returns the public endpoint hostname in Tencent Cloud When diarkis process is ready (diarkis.OnReady(callback)), you set this value to server.SetPublicEndPoint(endpoint)

func IndexOf

func IndexOf(array []string, me string) int

IndexOf Returns an index of a given element in the given array of strings

func Int16SliceEqual

func Int16SliceEqual(v1 []int16, v2 []int16) bool

Int16SliceEqual compares two slices and returns true if all the elements in the arrays match.

func Int32SliceEqual

func Int32SliceEqual(v1 []int32, v2 []int32) bool

Int32SliceEqual compares two slices and returns true if all the elements in the arrays match.

func Int64SliceEqual

func Int64SliceEqual(v1 []int64, v2 []int64) bool

Int64SliceEqual compares two slices and returns true if all the elements in the arrays match.

func Int8SliceEqual

func Int8SliceEqual(v1 []int8, v2 []int8) bool

Int8SliceEqual compares two slices and returns true if all the elements in the arrays match.

func IntSliceEqual

func IntSliceEqual(v1 []int, v2 []int) bool

IntSliceEqual compares two slices and returns true if all the elements in the arrays match.

func InterfaceEqual

func InterfaceEqual(d1 interface{}, d2 interface{}) bool

InterfaceEqual compares two interface{} variables and returns true, if the two variables have the same value.

func InterfaceSliceEqual

func InterfaceSliceEqual(v1 []interface{}, v2 []interface{}) bool

InterfaceSliceEqual compares two arrays of interface{} and returns true, if all the elements are equal values.

func IsArray

func IsArray(data interface{}) bool

IsArray returns a true if the given data interface{} is an array (slice).

func IsNullBytes

func IsNullBytes(buf []byte) bool

IsNullBytes returns true if the given byte array contains only x00

func IsPrimitiveDataType

func IsPrimitiveDataType(v interface{}) bool

IsPrimitiveDataType returns true if the given value is a primitive.

Data types that returns true are:

┌─────────┐
│    uint │
├─────────┤
│   uint8 │
├─────────┤
│  uint16 │
├─────────┤
│  uint32 │
├─────────┤
│  uint64 │
├─────────┤
│     int │
├─────────┤
│    int8 │
├─────────┤
│   int16 │
├─────────┤
│   int32 │
├─────────┤
│   int64 │
├─────────┤
│ float32 │
├─────────┤
│ float64 │
├─────────┤
│  string │
├─────────┤
│    bool │
├─────────┤
│  []byte │
└─────────┘

func LeadingZero

func LeadingZero(num int, digit int) string

LeadingZero Returns a string with leading 0

func NanoSecHex

func NanoSecHex() string

NanoSecHex Converts the unix timestamp in nano seconds to a hex string - Length of the returned string is always 16

func NanoSecRandHex

func NanoSecRandHex() string

NanoSecRandHex replaces the first 1 byte of unix timestamp in nano seconds to random bytes and converts it to a hex string - Length of the returned string is always 16

func NewError

func NewError(message interface{}, vars ...interface{}) error

NewError creates a new error with given error code, message and stack trace.

The error message is a formatted string with variables.

The same syntax as fmt.Sprintf

Example:

errMessage := "Some error occurred: VariableOne:%v VariableTwo:%s"

var1 := 100

var2 := "Something bad happened"

err := NewError(errMessage, var1, var2)

Parameters

message - Error message as a string or an error.
...vars - optional variables for the error message.

func NowMilliseconds

func NowMilliseconds() int64

NowMilliseconds Returns a Unix timestamp in milliseconds

func NowNanoseconds

func NowNanoseconds() int64

NowNanoseconds Returns a Unix timestamp in nanoseconds

func NowSeconds

func NowSeconds() int64

NowSeconds Returns a Unix timestamp in seconds

func Parallel

func Parallel(funcs []func(func(error)), done func(error))

Parallel executes multiple functions in parallel and calls done when all functions are finished

func ParseID

func ParseID(id string) (string, []string, error)

ParseID Returns unique ID and mesh node address list from an ID created by GetID()

func RandomInt

func RandomInt(min int, max int) int

RandomInt Returns a random int between min and max

func ReadFromTmp

func ReadFromTmp(name string) string

ReadFromTmp reads from a file under /tmp/ - The file must have a prefix of "DIARKIS_"

func RemoveErrorStackTrace

func RemoveErrorStackTrace(message string) string

RemoveErrorStackTrace removes error stack traces from the formatted error created by Diarkis' util.NewError.

func ReverseArray

func ReverseArray[T any](array []T) []T

ReverseArray reverses an array and returns it.

func ReverseBytes

func ReverseBytes(bytes []byte) []byte

ReverseBytes Reverses byte array

func RmSpaces

func RmSpaces(str string) string

RmSpaces Removes all spaces in a string - performs a single allocation, but may grossly over-allocate if the source string is mainly whitespace

func SetEnv

func SetEnv(name string, val string)

SetEnv sets an environment variable w/ the given name all env name will have a prefix of "DIARKIS_"

func Setup

func Setup()

Setup [INTERNAL USE ONLY] set up util package in diarkis

func StackError

func StackError(err error, errs ...error) error

StackError adds another error to the given error to create a stack of multiple errors.

[IMPORTANT] Errors should be formatted errors created by Diarkis' util.NewError

Parameters

err  - Anchor error for the other errors to join.
       If the error given is nil, the function returns nil.
errs - Optional errors to stack on the anchor error.
       If nil is given, the nil will be ignored.

func StrConcat

func StrConcat(strlist ...string) string

StrConcat concatenates strings

func ToBool

func ToBool(v interface{}) (bool, bool)

ToBool returns the given value of interface{} as bool.

[IMPORTANT] The second returned value is true if the value exists
            and the data type of the value is the same as specified data type.

func ToBoolArray

func ToBoolArray(data interface{}) ([]bool, bool)

ToBoolArray returns given interface{} as an array of bool.

[IMPORTANT] The second returned value indicates if the value is valid or not.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.

func ToBytes

func ToBytes(v interface{}) ([]byte, bool)

ToBytes returns the given value of interface{} as byte array.

[IMPORTANT] If the value is base64 encoded string, it will be auto-converted and returned as a byte array.
            The second value will be true in this case.
[IMPORTANT] The second returned value is true if the value exists
            and the data type of the value is the same as specified data type.

func ToBytesArray

func ToBytesArray(data interface{}) ([][]byte, bool)

ToBytesArray returns given interface{} as an array of bytes.

[IMPORTANT] The second returned value indicates if the value is valid or not.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.

func ToFixed

func ToFixed(num float64, precision int) string

ToFixed Returns a fixed precision of decimal number as a string

func ToFloat32

func ToFloat32(v interface{}) (float32, bool)

ToFloat32 returns the given value of interface{} as float64.

[IMPORTANT] The second returned value indicates if the value is valid or not.
[IMPORTANT] If the value is float64, it will be auto-converted and returned as the specified data type.
            The second returned value will be true in this case.
[IMPORTANT] The second returned value is true if the value exists
            and the data type of the value is the same as specified data type.

func ToFloat32Array

func ToFloat32Array(data interface{}) ([]float32, bool)

ToFloat32Array returns given interface{} as an array of float32.

[IMPORTANT] The second returned value indicates if the value is valid or not.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.

func ToFloat64

func ToFloat64(v interface{}) (float64, bool)

ToFloat64 returns the given value of interface{} as float64.

[IMPORTANT] The second returned value indicates if the value is valid or not.
[IMPORTANT] If the value is float64, it will be auto-converted and returned as the specified data type.
            The second returned value will be true in this case.
[IMPORTANT] The second returned value is true if the value exists
            and the data type of the value is the same as specified data type.

func ToFloat64Array

func ToFloat64Array(data interface{}) ([]float64, bool)

ToFloat64Array returns given interface{} as an array of float64.

[IMPORTANT] The second returned value indicates if the value is valid or not.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.

func ToInt

func ToInt(v interface{}) (int, bool)

ToInt returns the given value of interface{} as int.

[IMPORTANT] The second returned value indicates if the value is valid or not.
[IMPORTANT] If the value is float64, it will be auto-converted and returned as the specified data type.
            The second returned value will be true in this case.
[IMPORTANT] The second returned value is true if the value exists
            and the data type of the value is the same as specified data type.

func ToInt16

func ToInt16(v interface{}) (int16, bool)

ToInt16 returns the given value of interface{} as int16.

[IMPORTANT] The second returned value indicates if the value is valid or not.
[IMPORTANT] If the value is float64, it will be auto-converted and returned as the specified data type.
            The second returned value will be true in this case.
[IMPORTANT] The second returned value is true if the value exists
            and the data type of the value is the same as specified data type.

func ToInt16Array

func ToInt16Array(data interface{}) ([]int16, bool)

ToInt16Array returns given interface{} as an array of int16.

[IMPORTANT] The second returned value indicates if the value is valid or not.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.

func ToInt32

func ToInt32(v interface{}) (int32, bool)

ToInt32 returns the given value of interface{} as int32.

[IMPORTANT] The second returned value indicates if the value is valid or not.
[IMPORTANT] If the value is float64, it will be auto-converted and returned as the specified data type.
            The second returned value will be true in this case.
[IMPORTANT] The second returned value is true if the value exists
            and the data type of the value is the same as specified data type.

func ToInt32Array

func ToInt32Array(data interface{}) ([]int32, bool)

ToInt32Array returns given interface{} as an array of int32.

[IMPORTANT] The second returned value indicates if the value is valid or not.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.

func ToInt64

func ToInt64(v interface{}) (int64, bool)

ToInt64 returns the given value of interface{} as uint64.

[IMPORTANT] The second returned value indicates if the value is valid or not.
[IMPORTANT] If the value is float64, it will be auto-converted and returned as the specified data type.
            The second returned value will be true in this case.
[IMPORTANT] The second returned value is true if the value exists
            and the data type of the value is the same as specified data type.

func ToInt64Array

func ToInt64Array(data interface{}) ([]int64, bool)

ToInt64Array returns given interface{} as an array of int64.

[IMPORTANT] The second returned value indicates if the value is valid or not.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.

func ToInt8

func ToInt8(v interface{}) (int8, bool)

ToInt8 returns the given value of interface{} as int8.

[IMPORTANT] The second returned value indicates if the value is valid or not.
[IMPORTANT] If the value is float64, it will be auto-converted and returned as the specified data type.
            The second returned value will be true in this case.
[IMPORTANT] The second returned value is true if the value exists
            and the data type of the value is the same as specified data type.

func ToInt8Array

func ToInt8Array(data interface{}) ([]int8, bool)

ToInt8Array returns given interface{} as an array of int8.

[IMPORTANT] The second returned value indicates if the value is valid or not.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.

func ToIntArray

func ToIntArray(data interface{}) ([]int, bool)

ToIntArray returns given interface{} as an array of string.

[IMPORTANT] The second returned value indicates if the value is valid or not.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.

func ToString

func ToString(v interface{}) (string, bool)

ToString returns the given value of interface{} as string.

[IMPORTANT] The second returned value is true if the value exists
            and the data type of the value is the same as specified data type.

func ToStringArray

func ToStringArray(data interface{}) ([]string, bool)

ToStringArray returns given interface{} as an array of string.

[IMPORTANT] The second returned value indicates if the value is valid or not.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.

func ToStringKeyBytesMap

func ToStringKeyBytesMap(d interface{}) (map[string][]byte, bool)

ToStringKeyBytesMap converts an interface to a map of byte array with string keys.

func ToStringKeyInt64Map

func ToStringKeyInt64Map(d interface{}) (map[string]int64, bool)

ToStringKeyInt64Map converts an intrerface to a map of int64 with string keys.

func ToStringKeyIntMap

func ToStringKeyIntMap(d interface{}) (map[string]int, bool)

ToStringKeyIntMap returns a map with string keys with int values. The second returned value indicates if the data is valid or not.

func ToStringKeyInterfaceMap

func ToStringKeyInterfaceMap(d interface{}) (map[string]interface{}, bool)

ToStringKeyInterfaceMap returns a map with string keys with interface values. The second returned value indicates if the data is valid or not.

func ToUint

func ToUint(v interface{}) (uint, bool)

ToUint returns the given value of interface{} as uint.

[IMPORTANT] The second returned value indicates if the value is valid or not.
[IMPORTANT] If the value is float64, it will be auto-converted and returned as the specified data type.
            The second returned value will be true in this case.
[IMPORTANT] The second returned value is true if the value exists
            and the data type of the value is the same as specified data type.

func ToUint16

func ToUint16(v interface{}) (uint16, bool)

ToUint16 returns the given value of interface{} as uint16.

[IMPORTANT] The second returned value indicates if the value is valid or not.
[IMPORTANT] If the value is float64, it will be auto-converted and returned as the specified data type.
            The second returned value will be true in this case.
[IMPORTANT] The second returned value is true if the value exists
            and the data type of the value is the same as specified data type.

func ToUint16Array

func ToUint16Array(data interface{}) ([]uint16, bool)

ToUint16Array returns given interface{} as an array of uint16.

[IMPORTANT] The second returned value indicates if the value is valid or not.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.

func ToUint32

func ToUint32(v interface{}) (uint32, bool)

ToUint32 returns the given value of interface{} as uint32.

[IMPORTANT] The second returned value indicates if the value is valid or not.
[IMPORTANT] If the value is float64, it will be auto-converted and returned as the specified data type.
            The second returned value will be true in this case.
[IMPORTANT] The second returned value is true if the value exists
            and the data type of the value is the same as specified data type.

func ToUint32Array

func ToUint32Array(data interface{}) ([]uint32, bool)

ToUint32Array returns given interface{} as an array of uint16.

[IMPORTANT] The second returned value indicates if the value is valid or not.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.

func ToUint64

func ToUint64(v interface{}) (uint64, bool)

ToUint64 returns the given value of interface{} as uint64.

[IMPORTANT] The second returned value indicates if the value is valid or not.
[IMPORTANT] If the value is float64, it will be auto-converted and returned as the specified data type.
            The second returned value will be true in this case.
[IMPORTANT] The second returned value is true if the value exists
            and the data type of the value is the same as specified data type.

func ToUint64Array

func ToUint64Array(data interface{}) ([]uint64, bool)

ToUint64Array returns given interface{} as an array of uint16.

[IMPORTANT] The second returned value indicates if the value is valid or not.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.

func ToUint8

func ToUint8(v interface{}) (uint8, bool)

ToUint8 returns the given value of interface{} as uint8.

[IMPORTANT] The second returned value indicates if the value is valid or not.
[IMPORTANT] If the value is float64, it will be auto-converted and returned as the specified data type.
            The second returned value will be true in this case.
[IMPORTANT] The second returned value is true if the value exists
            and the data type of the value is the same as specified data type.

func ToUint8Array

func ToUint8Array(data interface{}) ([]uint8, bool)

ToUint8Array returns given interface{} as an array of uint8.

[IMPORTANT] The second returned value indicates if the value is valid or not.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.

func ToUintArray

func ToUintArray(data interface{}) ([]uint, bool)

ToUintArray returns given interface{} as an array of uint.

[IMPORTANT] The second returned value indicates if the value is valid or not.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.

func Uint16SliceEqual

func Uint16SliceEqual(v1 []uint16, v2 []uint16) bool

Uint16SliceEqual compares two slices and returns true if all the elements in the arrays match.

func Uint32SliceEqual

func Uint32SliceEqual(v1 []uint32, v2 []uint32) bool

Uint32SliceEqual compares two slices and returns true if all the elements in the arrays match.

func Uint64SliceEqual

func Uint64SliceEqual(v1 []uint64, v2 []uint64) bool

Uint64SliceEqual compares two slices and returns true if all the elements in the arrays match.

func Uint8SliceEqual

func Uint8SliceEqual(v1 []uint8, v2 []uint8) bool

Uint8SliceEqual compares two slices and returns true if all the elements in the arrays match.

func UintSliceEqual

func UintSliceEqual(v1 []uint, v2 []uint) bool

UintSliceEqual compares two slices and returns true if all the elements in the arrays match.

func Waterfall

func Waterfall(funcs []func(func(error)), done func(error))

Waterfall calls multiple functions in the order of the funcs array given and calls done func when finished.

func WriteToTmp

func WriteToTmp(name string, val string)

WriteToTmp writes a string to a file under /tmp/ - The file with have a prefix of "DIARKIS_"

func ZuluTimeFormat

func ZuluTimeFormat(now time.Time) string

ZuluTimeFormat returns a string of time in UTC Zulu format: RFC 3339

type Await

Await represents asynchronous wait group

type Await struct {
    sync.WaitGroup
}

func Async

func Async(taskNum int) *Await

Async returns await struct for asynchronous operations:

Usage Example

await := util.Async(2)
go func() {
  asynchronousOperation(func() {
    await.Done()
  })
}
go func() {
  asynchronousOperation(func() {
    await.Done()
  })
}
// this will block until all asynchronous operations are marked by await.Done()
await.Wait()
// all asynchronous operations are done now
finish()

type Parcel

Parcel represents a map of primitive data with string keys for safe data transportation such as mesh etc.

type Parcel struct {
    sync.RWMutex
    // contains filtered or unexported fields
}

func NewParcel

func NewParcel() *Parcel

NewParcel creates a new parcel instance.

func (*Parcel) Add

func (p *Parcel) Add(key string, value interface{}) bool

Add stores a new value or replace an existing value along with its key. The value MUST be of a primitive data type.

func (*Parcel) Export

func (p *Parcel) Export() map[string]interface{}

Export returns a copy of stored keys and values.

func (*Parcel) Remove

func (p *Parcel) Remove(key string) bool

Remove deletes a stored key along with its value.

type StringArray

StringArray represents an array of strings that is goroutine safe without the use of mutex lock

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

func NewStringArray

func NewStringArray() *StringArray

NewStringArray creates a new StringArray instance.

func NewStringArrayFromExportedData

func NewStringArrayFromExportedData(data string) *StringArray

NewStringArrayFromExportedData creates a new StringArray instance from exported StringArray raw data.

func (*StringArray) Clear

func (sa *StringArray) Clear()

Clear resets and deletes all elements from the array.

func (*StringArray) Delete

func (sa *StringArray) Delete(value string) bool

Delete removes the given string value from the array and returns true. Returns false if the value was not found in the array.

func (*StringArray) Export

func (sa *StringArray) Export() string

Export returns the raw data as a string for NewStringArray(data string) *StringArray.

func (*StringArray) GetAt

func (sa *StringArray) GetAt(index int) string

GetAt returns the element from the array at the given index. Returns an empty string if the given index is invalid.

func (*StringArray) GetIndex

func (sa *StringArray) GetIndex(value string) int

GetIndex returns the index of the given string value in the array. Returns -1 if the given string value does not exist in the array.

func (*StringArray) Length

func (sa *StringArray) Length() int

Length returns the length of the array.

func (*StringArray) Pop

func (sa *StringArray) Pop() string

Pop returns the first element of the array and removes it from the array. Returns an empty string if there is nothing to pop from the array.

func (*StringArray) Push

func (sa *StringArray) Push(value string)

Push pushes a given string value at the end of the array.

type StringMap

StringMap represents a map with string key and string value that is goroutine safe without the use of mutex lock. map[string]string

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

func NewStringMap

func NewStringMap() *StringMap

NewStringMap creates a new StringMap instance.

func NewStringMapFromExportedData

func NewStringMapFromExportedData(data string) *StringMap

NewStringMapFromExportedData creates a new StringMap instance from exported StringMap raw data.

func (*StringMap) Clear

func (sm *StringMap) Clear()

Clear resets and clears all keys and their values.

func (*StringMap) Delete

func (sm *StringMap) Delete(key string) bool

Delete removes the key and its value from the map. Returns false if the key does not exist in the map.

func (*StringMap) Export

func (sm *StringMap) Export() string

Export returns the raw data as a string to be used by NewStringMapFromExportedData.

func (*StringMap) Get

func (sm *StringMap) Get(key string) string

Get returns the value associated with the given key. Returns an empty string if the key does not exist in the map

func (*StringMap) Length

func (sm *StringMap) Length() int

Length returns how may keys the map has.

func (*StringMap) Set

func (sm *StringMap) Set(key string, value string)

Set assigns the given value to the given key.