package myconf import ( "fmt" "github.com/spf13/viper" ) var ( vp = viper.New() ) func LoadFile(confFile string, conf interface{}) { vp.SetConfigFile(confFile) err := vp.ReadInConfig() if err != nil { panic(fmt.Errorf("read file fail: %s", err)) } err = vp.Unmarshal(conf) if err != nil { panic(fmt.Errorf("parse file fail: %s", err)) } } func Conf() *viper.Viper { return vp }