gconfig.go
func Load() (*GConfig, error) {

	flag.Parse()

	gc := new(GConfig)
	gc.Profile = loadProfile()

	p, err := loadPath()
	if err != nil {
		return configError(err, "Error reading config directory path %s", p)
	}

	files, err := ioutil.ReadDir(p)
	if err != nil {
		return configError(err, "Error reading config directory in path %s", cpath)
	}
	if len(files) == 0 {
		return configError(ErrConfigFileRequired, "Config file not found in path %s", cpath)
	}

	//read individual config file
	for _, f := range files {
		cfpath := filepath.Join(p, f.Name())
		pf := fmt.Sprintf("application-%s.properties", gc.Profile)
		if f.Name() == StandardPropFileName || pf == f.Name() {
			cf, err := readPropertyFile(f, cfpath)
			if err != nil {
				return configError(err, "Error opening config file %s", f)
			}
			gc.addConfigFile(cf)
		}
	}

	Gcg = gc

	//do a final check if loaded config has any values
	if gc.isEmpty() {
		log.Printf("Configuration loaded, but empty for profile: '%s'\n", Gcg.Profile)
	} else {
		log.Printf("Configuration loaded for profile %s\n", Gcg.Profile)
	}

	return gc, nil
}
func Load() (*GConfig, error) {

	flag.Parse()

	gc := new(GConfig)
	gc.Profile = loadProfile()

	p, err := loadPath()
	if err != nil {
		return configError(err, "Error reading config directory path %s", p)
	}

	files, err := ioutil.ReadDir(p)
	if err != nil {
		return configError(err, "Error reading config directory in path %s", cpath)
	}
	if len(files) == 0 {
		return configError(ErrConfigFileRequired, "Config file not found in path %s", cpath)
	}

	//read individual config file
	for _, f := range files {
		cfpath := filepath.Join(p, f.Name())
		pf := fmt.Sprintf("application-%s.properties", gc.Profile)
		if f.Name() == StandardPropFileName || pf == f.Name() {
			cf, err := readPropertyFile(f, cfpath)
			if err != nil {
				return configError(err, "Error opening config file %s", f)
			}
			gc.addConfigFile(cf)
		}
	}

	Gcg = gc

	//do a final check if loaded config has any values
	if gc.isEmpty() {
		log.Printf("Configuration loaded, but empty for profile: '%s'\n", Gcg.Profile)
	} else {
		log.Printf("Configuration loaded for profile %s\n", Gcg.Profile)
	}

	return gc, nil
}
func Load ( ) ( * GConfig , error ) { flag . Parse ( ) gc := new ( GConfig ) gc . Profile = loadProfile ( ) p , err := loadPath ( ) if err != nil { return configError ( err , " " , p ) } files , err := ioutil . ReadDir ( p ) if err != nil { return configError ( err , " " , cpath ) } if len ( files ) == 0 { return configError ( ErrConfigFileRequired , " " , cpath ) } //read individual config file for _ , f := range files { cfpath := filepath . Join ( p , f . Name ( ) ) pf := fmt . Sprintf ( " " , gc . Profile ) if f . Name ( ) == StandardPropFileName || pf == f . Name ( ) { cf , err := readPropertyFile ( f , cfpath ) if err != nil { return configError ( err , " " , f ) } gc . addConfigFile ( cf ) } } Gcg = gc //do a final check if loaded config has any values if gc . isEmpty ( ) { log . Printf ( " \n " , Gcg . Profile ) } else { log . Printf ( " \n " , Gcg . Profile ) } return gc , nil }
// Load reads all the properties and creates GConfig representation. It loads
// config data based on passed in flags or environment variables. If none is
// defined it uses default values.
Load reads all the properties and creates GConfig representation . It loads config data based on passed in flags or environment variables . If none is defined it uses default values .