add user routes

This commit is contained in:
2026-09-04 23:03:50 +08:00
parent fe8ba74c5f
commit 4688c10585
12 changed files with 579 additions and 11 deletions

View File

@@ -2,6 +2,7 @@ package db
import (
"encoding/json"
"fmt"
"os"
"sync"
)
@@ -10,6 +11,13 @@ type Database struct {
Users map[string][]map[string]any `json:"Users"`
}
type UserIdType string
const (
UserId UserIdType = "userId"
Bid UserIdType = "bid"
)
var (
DB Database
mu sync.Mutex
@@ -45,3 +53,16 @@ func Save() {
os.WriteFile(tmp, data, 0644)
os.Rename(tmp, path)
}
func FindUser(id string, idType ...UserIdType) map[string]any {
key := UserId
if len(idType) > 0 {
key = idType[0]
}
for _, user := range DB.Users[os.Getenv("SERVER")] {
if fmt.Sprintf("%v", user[string(key)]) == id {
return user
}
}
return nil
}