gin-blog/pkg/setting/setting.go

21 lines
326 B
Go
Raw Permalink Normal View History

2021-05-28 10:41:12 +00:00
package setting
import "github.com/spf13/viper"
type Setting struct {
vp *viper.Viper
}
func NewSetting() (*Setting, error) {
vp := viper.New()
vp.SetConfigName("config")
vp.AddConfigPath("configs/")
vp.SetConfigType("yaml")
err := vp.ReadInConfig()
if err != nil {
return nil, err
}
return &Setting{vp}, nil
}