Exemplo n.º 1
0
// 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
}