mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-03-01 00:35:36 +08:00
读取角色配置表
This commit is contained in:
52
gdconf/check_json_valid_test.go
Normal file
52
gdconf/check_json_valid_test.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package gdconf
|
||||
|
||||
import (
|
||||
"github.com/hjson/hjson-go/v4"
|
||||
"hk4e/common/config"
|
||||
"hk4e/pkg/logger"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func CheckJsonLoop(path string, errorJsonFileList *[]string, totalJsonFileCount *int) {
|
||||
fileList, err := os.ReadDir(path)
|
||||
if err != nil {
|
||||
logger.LOG.Error("open dir error: %v", err)
|
||||
return
|
||||
}
|
||||
for _, file := range fileList {
|
||||
fileName := file.Name()
|
||||
if file.IsDir() {
|
||||
CheckJsonLoop(path+"/"+fileName, errorJsonFileList, totalJsonFileCount)
|
||||
}
|
||||
if !strings.Contains(fileName, ".json") {
|
||||
continue
|
||||
}
|
||||
fileData, err := os.ReadFile(path + "/" + fileName)
|
||||
if err != nil {
|
||||
logger.LOG.Error("open file error: %v", err)
|
||||
continue
|
||||
}
|
||||
var obj any
|
||||
err = hjson.Unmarshal(fileData, &obj)
|
||||
if err != nil {
|
||||
*errorJsonFileList = append(*errorJsonFileList, path+"/"+fileName+", err: "+err.Error())
|
||||
}
|
||||
*totalJsonFileCount++
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckJsonValid(t *testing.T) {
|
||||
config.InitConfig("./application.toml")
|
||||
logger.InitLogger("test", config.CONF.Logger)
|
||||
errorJsonFileList := make([]string, 0)
|
||||
totalJsonFileCount := 0
|
||||
CheckJsonLoop("./game_data_config/json", &errorJsonFileList, &totalJsonFileCount)
|
||||
for _, v := range errorJsonFileList {
|
||||
logger.LOG.Info("%v", v)
|
||||
}
|
||||
logger.LOG.Info("err json file count: %v, total count: %v", len(errorJsonFileList), totalJsonFileCount)
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
Reference in New Issue
Block a user