mirror of
https://github.com/Walter-Sparrow/lunar-tear.git
synced 2026-07-02 13:53:41 +03:00
22 lines
431 B
Go
22 lines
431 B
Go
package utils
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
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
|
|
}
|