20 lines
357 B
Go
20 lines
357 B
Go
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))
|
|
}
|
|
}
|