game_sync/common/functions.go

30 lines
424 B
Go

package common
import (
"fmt"
"github.com/spf13/viper"
)
var paths = []string{
".",
"./etc",
"./config",
}
func GetViper(name, filetype string) *viper.Viper {
vp := viper.New()
// 配置文件
vp.SetConfigName(name)
vp.SetConfigType(filetype)
for _, v := range paths {
vp.AddConfigPath(v)
}
err := vp.ReadInConfig()
if err != nil {
panic(fmt.Errorf("fatal error config file: %w", err))
}
return vp
}