gin-blog/pkg/setting/setting.go
2021-05-28 18:41:12 +08:00

21 lines
326 B
Go

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
}