main
lzf 2024-06-20 11:00:14 +08:00
parent 2b7c5848fe
commit a5fe1f32db
2 changed files with 14 additions and 5 deletions

View File

@ -1,4 +1,4 @@
package mycrypto
package mycommon
import (
"crypto/md5"

View File

@ -5,15 +5,24 @@ import (
"github.com/spf13/viper"
)
var (
vp *viper.Viper
)
func Init(confPath string, conf interface{}) {
v := viper.New()
v.SetConfigFile(confPath)
err := v.ReadInConfig()
vp = viper.New()
vp.SetConfigFile(confPath)
err := vp.ReadInConfig()
if err != nil {
panic(fmt.Errorf("读取配置文件失败 %s", err))
}
err = v.Unmarshal(conf)
err = vp.Unmarshal(conf)
if err != nil {
panic(fmt.Errorf("解析配置文件失败 %s", err))
}
}
func Conf() *viper.Viper {
return vp
}