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
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
CmdFieldDisappear The command ID for built-in field push
const CmdFieldDisappear uint16 = 123
CmdFieldReconn The command ID for built-in field push
const CmdFieldReconn uint16 = 122
CmdFieldSpawn The command ID for built-in field push
const CmdFieldSpawn uint16 = 124
CmdFieldSync The command ID for build-in field command
const CmdFieldSync uint16 = 121
CmdFieldSyncInit The command ID of built-in field command
const CmdFieldSyncInit uint16 = 120
CmdFindRooms The command ID of built-in message to room support command
const CmdFindRooms uint16 = 116
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
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
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
CmdUpdateRoomProp The command ID of built-in proerty update command
const CmdUpdateRoomProp uint16 = 107
MeshFieldReconn Mesh network command ID
const MeshFieldReconn uint16 = 50
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
MeshMatchingRemove Mesh network command ID
const MeshMatchingRemove uint16 = 42
MeshMigrate Mesh network command ID
const MeshMigrate uint16 = 80
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
MeshRoomBackupUpdate Mesh network command ID
const MeshRoomBackupUpdate uint16 = 13
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
MeshSessionCreate Mesh network command ID for sending session data from HTTP to TCP/UDP
const MeshSessionCreate uint16 = 20
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
func AddrToBytes(addr string) ([]byte, error)
AddrToBytes Converts address (address:port) string to byte array
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 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 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 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 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 IndexOf(array []string, me string) int
IndexOf Returns an index of a given element in the given array of strings
func IsNullBytes(buf []byte) bool
IsNullBytes returns true if the given byte array contains only x00
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 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 "DIAKRIS_"
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 overallocate 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 StrConcat(strlist ...string) string
StrConcat Concatnates strings
func ToFixed(num float64, precision int) string
ToFixed Returns a fixed precision of decimal number as a string
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 Retuns 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 opertions:
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()