Пример #1
0
// Load reads the configuration from a YAML file structure. If path is empty
// this method reads from the configuration file specified by the '-c' command
// line flag.
func Load(path string) (*common.Config, error) {
	var config *common.Config
	var err error

	if path == "" {
		config, err = common.LoadFiles(configfiles.list...)
	} else {
		config, err = common.LoadFile(path)
	}
	if err != nil {
		return nil, err
	}

	return common.MergeConfigs(
		defaults,
		config,
		overwrites,
	)
}
Пример #2
0
// Load reads the configuration from a YAML file structure. If path is empty
// this method reads from the configuration file specified by the '-c' command
// line flag.
func Load(path string) (*common.Config, error) {
	var config *common.Config
	var err error

	cfgpath := ""
	if *configPath != "" {
		cfgpath = *configPath
	} else if *homePath != "" {
		cfgpath = *homePath
	}

	if path == "" {
		list := []string{}
		for _, cfg := range configfiles.list {
			if !filepath.IsAbs(cfg) {
				list = append(list, filepath.Join(cfgpath, cfg))
			} else {
				list = append(list, cfg)
			}
		}
		config, err = common.LoadFiles(list...)
	} else {
		if !filepath.IsAbs(path) {
			path = filepath.Join(cfgpath, path)
		}
		config, err = common.LoadFile(path)
	}
	if err != nil {
		return nil, err
	}

	return common.MergeConfigs(
		defaults,
		config,
		overwrites,
	)
}