init
This commit is contained in:
19
myconf/conf.go
Normal file
19
myconf/conf.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package myconf
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
func Init(confPath string, conf interface{}) {
|
||||
v := viper.New()
|
||||
v.SetConfigFile(confPath)
|
||||
err := v.ReadInConfig()
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("读取配置文件失败 %s", err))
|
||||
}
|
||||
err = v.Unmarshal(conf)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("解析配置文件失败 %s", err))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user