package setting import ( "bytes" "speech-nlu-parse/pkg/consul" "github.com/spf13/viper" ) // TODO consul的地址和token // var ( // 默认本地环境的地址 // consulURL = "http://172.28.5.39:8500" // token = "092288b5-824f-854c-39aa-a958afd9a633" // ) type Setting struct { vp *viper.Viper } func NewSetting(consulAddr, consulToken string, configs ...string) (*Setting, error) { vp := viper.New() vp.SetConfigType("yaml") configContent := consul.GetKV(consulAddr, consulToken, configs...) err := vp.ReadConfig(bytes.NewBuffer(configContent)) if err != nil { return nil, err } s := &Setting{ vp: vp, } return s, nil }