func (c *client) resolveProfile() string {
	if v := os.Getenv(EnvConfigProfile); v != "" {
		return v
	}
	return c.bootstrap.Profile
}
Profile returns the resolved value of the profile.  It will
either use the CLUSTER_PROFILE env variable or fallback to
the specified default value as a fallback
package config
import (
	"errors"
	"fmt"
	"github.com/ContainX/go-utils/encoding"
	"github.com/ContainX/go-utils/envsubst"
	"github.com/ContainX/go-utils/httpclient"
	"os"
	"strings"
)
const (
	EnvConfigProfile = "CONFIG_PROFILE"
	EnvConfigServerURI = "CONFIG_SERVER_URI"
	UriDefault = "http://localhost:8888"
	ProfileDefault = "default"
	LabelDefault = "master"
	configPathFmt = "%s/%s/%s-%s.%s"
	extJSON       = "json"
	extPROP       = "properties"
	extYAML       = "yml"
)
var (
	NameNotDeclaredErr = errors.New("Name must be declared")
	FileNotDeclaredErr = errors.New("Filename must have a value")
)
type ConfigClient interface {
	Fetch(target interface{}) error
	FetchWithSubstitution(target interface{}) error
	FetchAsMap() (map[string]string, error)
	FetchAsJSON() (string, error)
	FetchAsYAML() (string, error)
	FetchAsProperties() (string, error)
	Bootstrap() *Bootstrap
}
type client struct {
	bootstrap *Bootstrap
}
type Bootstrap struct {
	URI string `json:"uri"`
	Context string `json:"context"`
	Profile string `json:"profile"`
	Name string `json:"name"`
	Label string `json:"label"`
	Username string `json:"username,omitempty"`
	Password string `json:"password,omitempty"`
}
func New(b Bootstrap) (ConfigClient, error) {
	if b.Name == "" {
		return nil, NameNotDeclaredErr
	}
	b.URI = defaultVal(b.URI, UriDefault)
	b.Profile = defaultVal(b.Profile, ProfileDefault)
	b.Label = defaultVal(b.Label, LabelDefault)
	client := &client{
		bootstrap: &b,
	}
	return client, nil
}
func LoadFromFile(filename string) (ConfigClient, error) {
	if filename == "" {
		return nil, FileNotDeclaredErr
	}
	f, err := os.Open(filename)
	if err != nil {
		return nil, err
	}
	defer f.Close()
	if encoder, err := encoding.NewEncoderFromFileExt(filename); err == nil {
		config := &Bootstrap{}
		if e := encoder.UnMarshal(f, config); e != nil {
			return nil, e
		}
		config.PopulateDefaultsIfEmpty()
		if config.Name == "" {
			return nil, NameNotDeclaredErr
		}
		client := &client{
			bootstrap: config,
		}
		return client, nil
	} else {
		return nil, err
	}
}
func (b *Bootstrap) PopulateDefaultsIfEmpty() {
	if b.URI == "" {
		b.URI = UriDefault
	}
	if b.Profile == "" {
		b.Profile = ProfileDefault
	}
	if b.Label == "" {
		b.Label = LabelDefault
	}
}
func defaultVal(s, d string) string {
	if s == "" {
		return d
	}
	return s
}