29 lines
428 B
Go
29 lines
428 B
Go
package myconf
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
var (
|
|
vp *viper.Viper
|
|
)
|
|
|
|
func Init(confPath string, conf interface{}) {
|
|
vp = viper.New()
|
|
vp.SetConfigFile(confPath)
|
|
err := vp.ReadInConfig()
|
|
if err != nil {
|
|
panic(fmt.Errorf("读取配置文件失败 %s", err))
|
|
}
|
|
|
|
err = vp.Unmarshal(conf)
|
|
if err != nil {
|
|
panic(fmt.Errorf("解析配置文件失败 %s", err))
|
|
}
|
|
}
|
|
|
|
func Conf() *viper.Viper {
|
|
return vp
|
|
}
|