示例#1
1
func loadConfig() {
	stormpath.InitLog()

	viper.SetConfigType("yaml")
	viper.AutomaticEnv()

	//Load bundled default config
	defaultConfig, err := Asset("config/web.stormpath.yaml")
	if err != nil {
		stormpath.Logger.Panicf("[ERROR] Couldn't load default bundle configuration: %s", err)
	}

	viper.ReadConfig(bytes.NewBuffer(defaultConfig))

	//Merge users custom configuration
	viper.SetConfigFile("stormpath.yaml")
	viper.AddConfigPath("~/.stormpath/")
	viper.AddConfigPath(".")
	err = viper.MergeInConfig()
	if err != nil {
		stormpath.Logger.Println("[WARN] User didn't provide custom configuration")
	}

	Config.Produces = viper.GetStringSlice("stormpath.web.produces")
	Config.BasePath = viper.GetString("stormpath.web.basePath")

	loadSocialConfig()
	loadCookiesConfig()
	loadEndpointsConfig()
	loadOAuth2Config()
}
示例#2
0
文件: viper.go 项目: dyweb/Ayi
// ViperReadAndMerge read specified config file and merge
func ViperReadAndMerge(path string) {
	// handle $HOME like viper does in `util` `absPathify`
	if strings.HasPrefix(path, "$HOME") {
		path = userHomeDir() + path[5:]
	}
	// TODO: handle other path problems
	path = filepath.FromSlash(path)
	if !FileExists(path) {
		log.WithField("file", path).Debug("Config file NOT found")
		return
	}
	viper.SetConfigFile(path)
	err := viper.MergeInConfig()
	if err != nil {
		log.WithField("file", path).Debug("Error merge config: " + err.Error())
		return
	}
	log.WithField("file", path).Debug("Config read and merged")
}