38 lines
570 B
Go
38 lines
570 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"sync"
|
|
)
|
|
|
|
var (
|
|
CacheClients = make(map[uint32]*Client)
|
|
mu sync.RWMutex
|
|
Groups = make(map[uint32]*Group)
|
|
)
|
|
|
|
func CacheGetClientById(id uint32) (*Client, error) {
|
|
mu.RLock()
|
|
defer mu.RUnlock()
|
|
|
|
client, ok := CacheClients[id]
|
|
if !ok {
|
|
return nil, fmt.Errorf("client %d not found", id)
|
|
}
|
|
return client, nil
|
|
}
|
|
|
|
func CacheSetClient(id uint32, client *Client) {
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
|
|
CacheClients[id] = client
|
|
}
|
|
|
|
func CacheDeleteClient(id uint32) {
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
|
|
delete(CacheClients, id)
|
|
}
|