add user routes
This commit is contained in:
21
db/db.go
21
db/db.go
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user