DelayNoMore/battle_srv/common/constants_loader.go

38 lines
901 B
Go
Raw Permalink Normal View History

2022-09-20 15:50:01 +00:00
package common
import (
"path/filepath"
"github.com/imdario/mergo"
"go.uber.org/zap"
. "dnmshared"
2022-09-20 15:50:01 +00:00
)
var Constants *constants
func MustParseConstants() {
fp := filepath.Join(Conf.General.AppRoot, "common/constants.json")
if isNotExist(fp) {
Logger.Fatal("common/constants.json文件不存在")
}
Constants = new(constants)
loadJSON(fp, Constants)
Logger.Debug("Conf.General.ServerEnv", zap.String("env", Conf.General.ServerEnv))
if Conf.General.ServerEnv == SERVER_ENV_TEST {
fp = filepath.Join(Conf.General.AppRoot, "common/constants_test.json")
if !isNotExist(fp) {
testConstants := new(constants)
loadJSON(fp, testConstants)
err := mergo.Merge(testConstants, Constants)
if nil != err {
panic(err)
}
2022-09-20 15:50:01 +00:00
Constants = testConstants
}
}
constantsPost()
// Logger.Debug("const", zap.Int("IntAuthTokenTTLSeconds", Constants.Player.IntAuthTokenTTLSeconds))
}