mycommon/myconf/conf.go

28 lines
398 B
Go
Raw Normal View History

2023-01-15 00:21:08 +08:00
package myconf
import (
"fmt"
"github.com/spf13/viper"
)
2024-06-20 11:00:14 +08:00
var (
2024-06-23 11:32:45 +08:00
vp = viper.New()
2024-06-20 11:00:14 +08:00
)
2024-06-23 11:32:45 +08:00
func LoadFile(confFile string, conf interface{}) {
vp.SetConfigFile(confFile)
2024-06-20 11:00:14 +08:00
err := vp.ReadInConfig()
2023-01-15 00:21:08 +08:00
if err != nil {
2024-06-23 11:32:45 +08:00
panic(fmt.Errorf("read file fail: %s", err))
2023-01-15 00:21:08 +08:00
}
2024-06-20 11:00:14 +08:00
err = vp.Unmarshal(conf)
2023-01-15 00:21:08 +08:00
if err != nil {
2024-06-23 11:32:45 +08:00
panic(fmt.Errorf("parse file fail: %s", err))
2023-01-15 00:21:08 +08:00
}
}
2024-06-20 11:00:14 +08:00
func Conf() *viper.Viper {
return vp
}