예제 #1
0
파일: cfgfile.go 프로젝트: ChongFeng/beats
// 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
파일: cfgfile.go 프로젝트: YaSuenag/hsbeat
// 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,
	)
}