changed param logic & add more routes

This commit is contained in:
2026-09-04 18:08:20 +08:00
parent a1569590bc
commit fe8ba74c5f
13 changed files with 267 additions and 12 deletions

65
master/master.go Normal file
View File

@@ -0,0 +1,65 @@
package master
import (
"bdgrp_go/pbutil"
"bdgrp_go/utils"
"bytes"
"compress/bzip2"
"io"
"os"
"path/filepath"
"sync"
)
var (
cache map[string]any
mu sync.RWMutex
)
func GetMaster() map[string]any {
mu.RLock()
defer mu.RUnlock()
if cache != nil {
return cache
}
mu.RUnlock()
return ReloadMaster()
}
func ReloadMaster() map[string]any {
server := os.Getenv("SERVER")
filePath := filepath.Join("resp", server, "suitemaster.bz2")
fileBuffer, err := os.ReadFile(filePath)
if err != nil {
return cache
}
decrypted, err := utils.Decrypt(fileBuffer)
if err != nil {
return cache
}
// bzip2 解壓
decompressed, err := io.ReadAll(bzip2.NewReader(bytes.NewReader(decrypted)))
if err != nil {
return cache
}
// protobuf decode → JSON map
msg, err := pbutil.Decode("SuiteMasterGetResponse", decompressed)
if err != nil {
return cache
}
result, err := pbutil.ToMap(msg)
if err != nil {
return cache
}
mu.Lock()
cache = result
mu.Unlock()
return cache
}