ManagementSystem/modules/cache/cache.go

39 lines
706 B
Go

package cache
import (
"sync"
"clickandjoin.app/managementsystem/modules/structs"
)
var socketClients = make(map[string]*structs.SocketClient)
var mu sync.RWMutex
func AddSocketClient(clientId string, socketClient *structs.SocketClient) {
mu.Lock()
socketClients[clientId] = socketClient
mu.Unlock()
}
func DeleteClient(clientId string) {
mu.Lock()
delete(socketClients, clientId)
mu.Unlock()
}
func GetSocketClients() map[string]*structs.SocketClient {
mu.RLock()
defer mu.RUnlock()
return socketClients
}
func GetSocketClient(clientId string) (socketClient *structs.SocketClient, ok bool) {
mu.RLock()
defer mu.RUnlock()
client, ok := socketClients[clientId]
return client, ok
}