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
= 10func AddrToBytes(addr string) ([]byte, error)
AddrToBytes Converts address (address:port) string to byte array
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(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(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(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(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(w int, text string, alignment int, isTop, connecting bool) string
CreateBox creates a box
func DeleteFromTmp(name string)
DeleteFromTmp removes a file under /tmp/ - The file must have a prefix of "DIARKIS_"
func FlattenErrorStackTrace(message string) string
FlattenErrorStackTrace replaces error stack traces' line breaks and convert them to a tab.
func Float32SliceEqual(v1 []float32, v2 []float32) bool
Float32SliceEqual compares two slices and returns true if all the elements in the arrays match.
func Float64SliceEqual(v1 []float64, v2 []float64) bool
Float64SliceEqual compares two slices and returns true if all the elements in the arrays match.
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() (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(id string) (string, error)
GetAddressFromAddressID returns encoded address as a string from an address ID created by CreateAddressID.
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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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() (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() (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() (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() (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() (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() (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() (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() (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(array []string, me string) int
IndexOf Returns an index of a given element in the given array of strings
func Int16SliceEqual(v1 []int16, v2 []int16) bool
Int16SliceEqual compares two slices and returns true if all the elements in the arrays match.
func Int32SliceEqual(v1 []int32, v2 []int32) bool
Int32SliceEqual compares two slices and returns true if all the elements in the arrays match.
func Int64SliceEqual(v1 []int64, v2 []int64) bool
Int64SliceEqual compares two slices and returns true if all the elements in the arrays match.
func Int8SliceEqual(v1 []int8, v2 []int8) bool
Int8SliceEqual compares two slices and returns true if all the elements in the arrays match.
func IntSliceEqual(v1 []int, v2 []int) bool
IntSliceEqual compares two slices and returns true if all the elements in the arrays match.
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(v1 []interface{}, v2 []interface{}) bool
InterfaceSliceEqual compares two arrays of interface{} and returns true, if all the elements are equal values.
func IsArray(data interface{}) bool
IsArray returns a true if the given data interface{} is an array (slice).
func IsNullBytes(buf []byte) bool
IsNullBytes returns true if the given byte array contains only x00
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(num int, digit int) string
LeadingZero Returns a string with leading 0
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() 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(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.
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() int64
NowMilliseconds Returns a Unix timestamp in milliseconds
func NowNanoseconds() int64
NowNanoseconds Returns a Unix timestamp in nanoseconds
func NowSeconds() int64
NowSeconds Returns a Unix timestamp in seconds
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(id string) (string, []string, error)
ParseID Returns unique ID and mesh node address list from an ID created by GetID()
func RandomInt(min int, max int) int
RandomInt Returns a random int between min and max
func ReadFromTmp(name string) string
ReadFromTmp reads from a file under /tmp/ - The file must have a prefix of "DIARKIS_"
func RemoveErrorStackTrace(message string) string
RemoveErrorStackTrace removes error stack traces from the formatted error created by Diarkis' util.NewError.
func ReverseArray[T any](array []T) []T
ReverseArray reverses an array and returns it.
func ReverseBytes(bytes []byte) []byte
ReverseBytes Reverses byte array
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(name string, val string)
SetEnv sets an environment variable w/ the given name all env name will have a prefix of "DIARKIS_"
func Setup()
Setup [INTERNAL USE ONLY] set up util package in diarkis
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(strlist ...string) string
StrConcat concatenates strings
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(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(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(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(num float64, precision int) string
ToFixed Returns a fixed precision of decimal number as a string
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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(d interface{}) (map[string][]byte, bool)
ToStringKeyBytesMap converts an interface to a map of byte array with string keys.
func ToStringKeyInt64Map(d interface{}) (map[string]int64, bool)
ToStringKeyInt64Map converts an intrerface to a map of int64 with string keys.
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(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(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(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(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(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(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(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(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(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(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(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(v1 []uint16, v2 []uint16) bool
Uint16SliceEqual compares two slices and returns true if all the elements in the arrays match.
func Uint32SliceEqual(v1 []uint32, v2 []uint32) bool
Uint32SliceEqual compares two slices and returns true if all the elements in the arrays match.
func Uint64SliceEqual(v1 []uint64, v2 []uint64) bool
Uint64SliceEqual compares two slices and returns true if all the elements in the arrays match.
func Uint8SliceEqual(v1 []uint8, v2 []uint8) bool
Uint8SliceEqual compares two slices and returns true if all the elements in the arrays match.
func UintSliceEqual(v1 []uint, v2 []uint) bool
UintSliceEqual compares two slices and returns true if all the elements in the arrays match.
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(name string, val string)
WriteToTmp writes a string to a file under /tmp/ - The file with have a prefix of "DIARKIS_"
func ZuluTimeFormat(now time.Time) string
ZuluTimeFormat returns a string of time in UTC Zulu format: RFC 3339
Await represents asynchronous wait group
type Await struct { sync.WaitGroup }
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()
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() *Parcel
NewParcel creates a new parcel instance.
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 (p *Parcel) Export() map[string]interface{}
Export returns a copy of stored keys and values.
func (p *Parcel) Remove(key string) bool
Remove deletes a stored key along with its value.
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() *StringArray
NewStringArray creates a new StringArray instance.
func NewStringArrayFromExportedData(data string) *StringArray
NewStringArrayFromExportedData creates a new StringArray instance from exported StringArray raw data.
func (sa *StringArray) Clear()
Clear resets and deletes all elements from the array.
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 (sa *StringArray) Export() string
Export returns the raw data as a string for NewStringArray(data string) *StringArray.
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 (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 (sa *StringArray) Length() int
Length returns the length of the array.
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 (sa *StringArray) Push(value string)
Push pushes a given string value at the end of the array.
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() *StringMap
NewStringMap creates a new StringMap instance.
func NewStringMapFromExportedData(data string) *StringMap
NewStringMapFromExportedData creates a new StringMap instance from exported StringMap raw data.
func (sm *StringMap) Clear()
Clear resets and clears all keys and their values.
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 (sm *StringMap) Export() string
Export returns the raw data as a string to be used by NewStringMapFromExportedData.
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 (sm *StringMap) Length() int
Length returns how may keys the map has.
func (sm *StringMap) Set(key string, value string)
Set assigns the given value to the given key.