use uuid for everything

This commit is contained in:
2026-04-12 14:19:46 +02:00
parent 18ebfd0416
commit 3be9619cca
9 changed files with 72 additions and 68 deletions
+10 -10
View File
@@ -9,17 +9,17 @@ import (
var (
mu sync.RWMutex
CacheUsers = make(map[uint32]*User)
CacheGroups = make(map[uint32]*Group)
CacheUsers = make(map[uuid.UUID]*User)
CacheGroups = make(map[uuid.UUID]*Group)
)
func CacheGetUserById(id uint32) (*User, error) {
func CacheGetUserById(id uuid.UUID) (*User, error) {
mu.RLock()
defer mu.RUnlock()
user, ok := CacheUsers[id]
if !ok {
return nil, fmt.Errorf("user %d not found", id)
return nil, fmt.Errorf("user %s not found", id)
}
return user, nil
}
@@ -43,7 +43,7 @@ func CacheSaveUser(user *User) {
CacheUsers[user.Id] = user
}
func CacheDeleteUser(id uint32) {
func CacheDeleteUser(id uuid.UUID) {
mu.Lock()
defer mu.Unlock()
@@ -57,7 +57,7 @@ func CacheSaveGroup(group *Group) {
CacheGroups[group.Id] = group
}
func CacheDeleteGroup(id uint32) {
func CacheDeleteGroup(id uuid.UUID) {
mu.Lock()
defer mu.Unlock()
delete(CacheGroups, id)
@@ -65,7 +65,7 @@ func CacheDeleteGroup(id uint32) {
func CacheAddConnection(a, b *User, conn *Connection) {
first, second := a, b
if a.Id > b.Id {
if a.Id.String() > b.Id.String() {
first, second = b, a
}
first.Mu.Lock()
@@ -78,7 +78,7 @@ func CacheAddConnection(a, b *User, conn *Connection) {
func CacheDeleteConnection(a, b *User, id uuid.UUID) {
first, second := a, b
if a.Id > b.Id {
if a.Id.String() > b.Id.String() {
first, second = b, a
}
first.Mu.Lock()
@@ -96,13 +96,13 @@ func CacheGetConnection(user *User, id uuid.UUID) (*Connection, bool) {
return conn, ok
}
func CacheGetGroup(id uint32) (*Group, error) {
func CacheGetGroup(id uuid.UUID) (*Group, error) {
mu.RLock()
defer mu.RUnlock()
group, ok := CacheGroups[id]
if !ok {
return nil, fmt.Errorf("group %d not found", id)
return nil, fmt.Errorf("group %s not found", id)
}
return group, nil