generated from root/miduo_server
80 lines
2.0 KiB
Go
80 lines
2.0 KiB
Go
package util
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/gogf/gf/os/gcache"
|
|
"github.com/gogf/gf/os/gfile"
|
|
"github.com/gogf/gf/util/gconv"
|
|
"github.com/jszwec/csvutil"
|
|
"gmanager/library/mongo/gameinfo"
|
|
"io/ioutil"
|
|
"strings"
|
|
)
|
|
|
|
// 删除零宽度无分隔符空间
|
|
func DelPrefix(data []byte) []byte {
|
|
if data == nil || len(data) < 4 {
|
|
return nil
|
|
}
|
|
UTF8_BOM := "\uFEFF"
|
|
if strings.HasPrefix(string(data), UTF8_BOM) {
|
|
data = data[3:]
|
|
}
|
|
return data
|
|
}
|
|
|
|
// item
|
|
func GetItemConfig() *gcache.Cache {
|
|
var c = gcache.New()
|
|
csvInput := gfile.GetBytes("./config/server/item.csv")
|
|
csvInput = DelPrefix(csvInput)
|
|
var itemConfigs []gameinfo.ItemConfig
|
|
if err := csvutil.Unmarshal(csvInput, &itemConfigs); err != nil {
|
|
fmt.Println("error:", err)
|
|
}
|
|
for _, itemConfig := range itemConfigs {
|
|
c.Set(gconv.String(itemConfig.Id), itemConfig.Note, 0)
|
|
}
|
|
return c
|
|
}
|
|
|
|
// RechargeCommodity
|
|
func GetRechargeCommodityConfig() *gcache.Cache {
|
|
var c = gcache.New()
|
|
csvInput := gfile.GetBytes("./config/server/RechargeCommodityConfig.csv")
|
|
csvInput = DelPrefix(csvInput)
|
|
var rechargeCommodityConfigs []gameinfo.RechargeCommodityConfig
|
|
if err := csvutil.Unmarshal(csvInput, &rechargeCommodityConfigs); err != nil {
|
|
fmt.Println("error:", err)
|
|
}
|
|
for _, rechargeCommodityConfig := range rechargeCommodityConfigs {
|
|
c.Set(gconv.String(rechargeCommodityConfig.Id), rechargeCommodityConfig, 0)
|
|
}
|
|
return c
|
|
}
|
|
|
|
// Reason
|
|
func GetReasonConfig() *gcache.Cache {
|
|
var c = gcache.New()
|
|
csvInput := gfile.GetBytes("./config/server/reason.csv")
|
|
csvInput = DelPrefix(csvInput)
|
|
var reasonConfigs []gameinfo.ReasonConfig
|
|
if err := csvutil.Unmarshal(csvInput, &reasonConfigs); err != nil {
|
|
fmt.Println("error:", err)
|
|
}
|
|
for _, reasonConfig := range reasonConfigs {
|
|
c.Set(gconv.String(reasonConfig.Id), reasonConfig, 0)
|
|
}
|
|
return c
|
|
}
|
|
|
|
func LoadAllFiles() {
|
|
path := "./config/server/"
|
|
fs,_:= ioutil.ReadDir(path)
|
|
for _,file:=range fs{
|
|
if !file.IsDir(){
|
|
name := file.Name()
|
|
fmt.Println(path+name)
|
|
}
|
|
}
|
|
} |