conf.go 379 Bytes
Newer Older
kzkzzzz's avatar
kzkzzzz committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
package conf

import (
	"fmt"
	"github.com/spf13/viper"
)

func LoadFromYaml(configFile string, conf interface{}) {
	v := viper.New()
	v.SetConfigFile(configFile)
	err := v.ReadInConfig()
	if err != nil {
		panic(fmt.Errorf("读取配置文件失败: %s", err))
	}

	err = v.Unmarshal(&conf)
	if err != nil {
		panic(fmt.Errorf("解析配置文件失败: %s", err))
	}
	return
}