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(client *Client) { mu.Lock() defer mu.Unlock() CacheClients[client.Id] = client } func CacheDeleteClient(id uint32) { mu.Lock() defer mu.Unlock() delete(CacheClients, id) } func CacheSetGroup() {} func CacheGetGroup(id uint32) (*Group, error) { mu.RLock() defer mu.RUnlock() group, ok := Groups[id] if !ok { return nil, fmt.Errorf("group %d not found", id) } return group, nil }