115 lines
2.3 KiB
Go
115 lines
2.3 KiB
Go
|
package config
|
|||
|
|
|||
|
import (
|
|||
|
"fmt"
|
|||
|
"io/ioutil"
|
|||
|
"strconv"
|
|||
|
"strings"
|
|||
|
|
|||
|
"sandc/app/eonline/internal/config/bright/serialization"
|
|||
|
Config "sandc/app/eonline/internal/config/config"
|
|||
|
|
|||
|
"github.com/go-kratos/kratos/v2/log"
|
|||
|
)
|
|||
|
|
|||
|
var (
|
|||
|
// 处理的特别数据
|
|||
|
PublicCheckNum uint32 // 最大验证数量,超过这个数量,新的用户将不再出现信息验证入口
|
|||
|
PublicCheckCoin int32 // 提交身份审核,提现奖励的钱/美分
|
|||
|
PublicVersionMin uint32
|
|||
|
|
|||
|
// 读表
|
|||
|
g_tables *Config.Tables // bin读表数据
|
|||
|
g_path *string
|
|||
|
)
|
|||
|
|
|||
|
func ConfigInit(path, env, ver_check *string) {
|
|||
|
log.Info("读取cvs配置文件开始")
|
|||
|
|
|||
|
g_path = path
|
|||
|
|
|||
|
loadConfig(ver_check)
|
|||
|
|
|||
|
checkConfig(env)
|
|||
|
|
|||
|
log.Info("读取cvs配置文件结束")
|
|||
|
}
|
|||
|
|
|||
|
func loadConfig(ver_check *string) {
|
|||
|
readBin(ver_check)
|
|||
|
}
|
|||
|
|
|||
|
func loader(file string) (*serialization.ByteBuf, error) {
|
|||
|
if bytes, err := ioutil.ReadFile(*g_path + file + ".bytes"); err != nil {
|
|||
|
return nil, err
|
|||
|
} else {
|
|||
|
return serialization.WrapByteBuf(bytes), nil
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
func readBin(ver_check *string) {
|
|||
|
var err error
|
|||
|
g_tables, err = Config.NewTables(loader)
|
|||
|
if err != nil {
|
|||
|
log.Fatal("readBin error: %s", err.Error())
|
|||
|
} else {
|
|||
|
log.Info("readBin success")
|
|||
|
}
|
|||
|
|
|||
|
log.Debugf("%+v", g_tables.Tbglobal.Get(100000))
|
|||
|
|
|||
|
// 处理的特别数据
|
|||
|
PublicCheckNum = 5000
|
|||
|
PublicCheckCoin = 500
|
|||
|
|
|||
|
PublicVersionMin = Version2int(ver_check)
|
|||
|
}
|
|||
|
|
|||
|
// 检查配置
|
|||
|
func checkConfig(env *string) {
|
|||
|
if *env != "qa" {
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
{
|
|||
|
var item *Config.ConfiguserState
|
|||
|
lst := g_tables.TbuserState.GetDataList()
|
|||
|
for i := 0; i < len(lst); i++ {
|
|||
|
item = lst[i]
|
|||
|
|
|||
|
if item.State < 0 || item.State > 1 {
|
|||
|
log.Infof("checkConfig error: userState table id[%d] State[%d] < 0 || > 1", item.Id, item.State)
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
log.Info("checkConfig结束")
|
|||
|
}
|
|||
|
|
|||
|
// 将二段、三段式版本号字符串,如“1.0”、“1.0.1”转换成6位数字
|
|||
|
func Version2int(ver *string) uint32 {
|
|||
|
strs := strings.Split(*ver, ".")
|
|||
|
|
|||
|
var err error
|
|||
|
var b, idx int
|
|||
|
var result, str string
|
|||
|
for idx, str = range strs {
|
|||
|
b, err = strconv.Atoi(str)
|
|||
|
if err == nil {
|
|||
|
result += fmt.Sprintf("%02d", b)
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
b, _ = strconv.Atoi(result)
|
|||
|
|
|||
|
for ; idx < 2; idx++ {
|
|||
|
b *= 100
|
|||
|
}
|
|||
|
|
|||
|
return uint32(b)
|
|||
|
}
|
|||
|
|
|||
|
func GetUserStateData() []*Config.ConfiguserState {
|
|||
|
return g_tables.TbuserState.GetDataList()
|
|||
|
}
|