mirror of
https://github.com/Walter-Sparrow/lunar-tear.git
synced 2026-07-02 13:53:41 +03:00
Add authentication server, dev CLI, Docker multi-service setup, and cross-platform improvements
This commit is contained in:
@@ -3,19 +3,20 @@ package utils
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"lunar-tear/server/internal/masterdata/memorydb"
|
||||
)
|
||||
|
||||
func ReadJSON[T any](filename string) ([]T, error) {
|
||||
path := filepath.Join("assets", "master_data", filename)
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("read %s: %w", path, err)
|
||||
}
|
||||
var out []T
|
||||
if err := json.Unmarshal(data, &out); err != nil {
|
||||
return nil, fmt.Errorf("unmarshal %s: %w", path, err)
|
||||
}
|
||||
return out, nil
|
||||
// ReadTable deserializes a master data table from the in-memory binary store.
|
||||
// The key is the snake_case table name as it appears in the binary header
|
||||
// (e.g. "m_weapon", "m_costume").
|
||||
func ReadTable[T any](key string) ([]T, error) {
|
||||
return memorydb.ReadTable[T](key)
|
||||
}
|
||||
|
||||
func EncodeJSONMaps(records ...map[string]any) (string, error) {
|
||||
jsonBytes, err := json.Marshal(records)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("json marshal maps: %w", err)
|
||||
}
|
||||
return string(jsonBytes), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user