示例#1
0
文件: config.go 项目: chop-dbhi/dcc
// setConfigPath set the primary source of configuration for the service.
func setConfigPath(v *viper.Viper, uri string) error {
	p, err := url.Parse(uri)

	if err != nil {
		return err
	}

	// Local path.
	if p.Scheme == "" {
		v.SetConfigFile(uri)
		return nil
	}

	// Consul.
	if p.Scheme == "consul" {
		ep := fmt.Sprintf("http://%s", p.Host)
		v.AddRemoteProvider("consul", ep, trimExt(p.Path))
		v.SetConfigType(filepath.Ext(p.Path)[1:])
		return nil
	}

	return nil
}