first commit
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package setting
|
||||
|
||||
import (
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
// Setting 封装 viper 配置读取能力。
|
||||
type Setting struct {
|
||||
vp *viper.Viper
|
||||
}
|
||||
|
||||
// NewSetting 初始化配置读取器,仅从 configs/config.yaml 读取配置。
|
||||
// 所有配置项一律在配置文件中直接填写,不支持环境变量覆盖。
|
||||
func NewSetting() (*Setting, error) {
|
||||
vp := viper.New()
|
||||
vp.AddConfigPath("configs/")
|
||||
vp.SetConfigName("config")
|
||||
vp.SetConfigType("yaml")
|
||||
if err := vp.ReadInConfig(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Setting{vp: vp}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user