// LoadConfigDir loads all the configurations in the given directory
// in alphabetical order.
196596
func LoadConfigDir(dir string, logger log.Logger) (*Config, error) {
	f, err := os.Open(dir)
	if err != nil {
		return nil, err
	}
	defer f.Close()

	fi, err := f.Stat()
	if err != nil {
		return nil, err
	}
	if !fi.IsDir() {
		return nil, fmt.Errorf("configuration path must be a directory: %q", dir)
	}

	var files []string
	err = nil
	for err != io.EOF {
		var fis []os.FileInfo
		fis, err = f.Readdir(128)
		if err != nil && err != io.EOF {
			return nil, err
		}

		for _, fi := range fis {
			// Ignore directories
			if fi.IsDir() {
				continue
			}

			// Only care about files that are valid to load.
			name := fi.Name()
			skip := true
			if strings.HasSuffix(name, ".hcl") {
				skip = false
			} else if strings.HasSuffix(name, ".json") {
				skip = false
			}
			if skip || isTemporaryFile(name) {
				continue
			}

			path := filepath.Join(dir, name)
			files = append(files, path)
		}
	}

	var result *Config
	for _, f := range files {
		config, err := LoadConfigFile(f, logger)
		if err != nil {
			return nil, errwrap.Wrapf(fmt.Sprintf("error loading %q: {{err}}", f), err)
		}

		if result == nil {
			result = config
		} else {
			result = result.Merge(config)
		}
	}

	return result, nil
}
564786
func loadConfig(path string) (config, error) {
	var ret config

	if path == "" {
		return ret, nil
	}

	file, err := os.Open(path)
	switch {
	case err == nil:
		defer file.Close()

		decoder := json.NewDecoder(file)
		if err = decoder.Decode(&ret); err != nil {
			return ret, errors.Annotate(err, "failed to decode file").Err()
		}
		return ret, nil

	case os.IsNotExist(err):
		// The file does not exist. We don't consider this an error, since the file
		// is optional.
		return ret, nil

	default:
		// An unexpected failure occurred.
		return ret, errors.Annotate(err, "failed to open file").Err()
	}
}
1218214
func LoadConfig() (*Config, tfdiags.Diagnostics) {
	var diags tfdiags.Diagnostics
	configVal := BuiltinConfig // copy
	config := &configVal

	if mainFilename, err := cliConfigFile(); err == nil {
		if _, err := os.Stat(mainFilename); err == nil {
			mainConfig, mainDiags := loadConfigFile(mainFilename)
			diags = diags.Append(mainDiags)
			config = config.Merge(mainConfig)
		}
	}

	if configDir, err := ConfigDir(); err == nil {
		if info, err := os.Stat(configDir); err == nil && info.IsDir() {
			dirConfig, dirDiags := loadConfigDir(configDir)
			diags = diags.Append(dirDiags)
			config = config.Merge(dirConfig)
		}
	}

	if envConfig := EnvConfig(); envConfig != nil {
		// envConfig takes precedence
		config = envConfig.Merge(config)
	}

	diags = diags.Append(config.Validate())

	return config, diags
}
788379
func (s *DjangoEngine) loadDirectory() (templateErr error) {
	dir, extension := s.directory, s.extension

	fsLoader, err := pongo2.NewLocalFileSystemLoader(dir) // I see that this doesn't read the content if already parsed, so do it manually via filepath.Walk
	if err != nil {
		return err
	}

	set := pongo2.NewSet("", fsLoader)
	set.Globals = getPongoContext(s.globals)

	s.mu.Lock()
	defer s.mu.Unlock()

	// Walk the supplied directory and compile any files that match our extension list.
	filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
		// Fix same-extension-dirs bug: some dir might be named to: "users.tmpl", "local.html".
		// These dirs should be excluded as they are not valid golang templates, but files under
		// them should be treat as normal.
		// If is a dir, return immediately (dir is not a valid golang template).
		if info == nil || info.IsDir() {

		} else {

			rel, err := filepath.Rel(dir, path)
			if err != nil {
				templateErr = err
				return err
			}

			ext := filepath.Ext(rel)
			if ext == extension {

				buf, err := ioutil.ReadFile(path)
				if err != nil {
					templateErr = err
					return err
				}
				name := filepath.ToSlash(rel)

				s.templateCache[name], templateErr = set.FromString(string(buf))

				if templateErr != nil {
					return templateErr
				}
			}

		}
		return nil
	})

	return
}
875728
func DefaultConfigDir() (string, error) {
	usr, err := user.Current()
	if err != nil {
		return "", err
	}
	return path.Join(usr.HomeDir, ".argocd"), nil
}
850788
func (m *Meta) RebaseConfigDir(root string) {
	if m.ConfigDir != "" && m.ConfigDir != "-" {
		m.ConfigDir = filepath.Join(root, filepath.FromSlash(m.ConfigDir))
	}
}
284537
func loadConfig() (*Config, error) {
	cfg, err := client.GetConfig()

	if err != nil {
		return nil, err
	}

	if cfg.Server == "" {
		cfg.Server = "https://textsecure-service.whispersystems.org:443"
	}

	if cfg.VerificationType == "" {
		cfg.VerificationType = "sms"
	}

	if cfg.StorageDir == "" {
		cfg.StorageDir = ".storage"
	}

	return cfg, nil
}
773894
func DefaultConfigDir() string {
	// Try to place the data folder in the user's home dir
	home := homeDir()
	if home != "" {
		if runtime.GOOS == "darwin" {
			return filepath.Join(home, "Library", "Signer")
		} else if runtime.GOOS == "windows" {
			appdata := os.Getenv("APPDATA")
			if appdata != "" {
				return filepath.Join(appdata, "Signer")
			} else {
				return filepath.Join(home, "AppData", "Roaming", "Signer")
			}
		} else {
			return filepath.Join(home, ".clef")
		}
	}
	// As we cannot guess a stable location, return empty and handle later
	return ""
}
809082
func LoadConfigFile(fileName string, moreFiles ...string) (c *ConfigFile, err error) {
	// Append files' name together.
	fileNames := make([]string, 1, len(moreFiles)+1)
	fileNames[0] = fileName
	if len(moreFiles) > 0 {
		fileNames = append(fileNames, moreFiles...)
	}

	c = newConfigFile(fileNames)

	for _, name := range fileNames {
		if err = c.loadFile(name); err != nil {
			return nil, err
		}
	}

	return c, nil
}
1255002
func (s *Engine) LoadDirectory(dir string, extension string) error {

	var templateErr error
	s.Templates = template.New(dir)
	s.Templates.Delims(s.Config.Left, s.Config.Right)

	filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
		if info == nil || info.IsDir() {

		} else {

			rel, err := filepath.Rel(dir, path)
			if err != nil {
				templateErr = err
				return err
			}

			ext := filepath.Ext(path)
			if ext == extension {

				buf, err := ioutil.ReadFile(path)
				if err != nil {
					templateErr = err
					return err
				}

				contents := string(buf)

				if err == nil {

					name := filepath.ToSlash(rel)
					tmpl := s.Templates.New(name)

					if s.Middleware != nil {
						contents, err = s.Middleware(name, contents)
					}
					if err != nil {
						templateErr = err
						return err
					}
					s.mu.Lock()
					// Add our funcmaps.
					if s.Config.Funcs != nil {
						tmpl.Funcs(s.Config.Funcs)
					}

					tmpl.Funcs(emptyFuncs).Parse(contents)
					s.mu.Unlock()
				}
			}

		}
		return nil
	})

	return templateErr
}
1073785
func LoadConfiguration(Path string) (map[string]string, error) {
	cfgMap := make(map[string]string)
	err := cfg.Load(Path, cfgMap)

	return cfgMap, err
}
611866
func XDGBaseDir(configFileName string) *configSource {
	skip := false
	// Look for config in standard XDG specified locations
	configFile, err := xdgbasedir.GetConfigFileLocation(configFileName)
	if err == nil {
		_, err := os.Stat(configFile)
		// Skip if config  file does not exist at default location
		skip = os.IsNotExist(err)
	}
	return &configSource{
		skip: skip,
		from: fmt.Sprintf("XDG base dir"),
		apply: func(baseConfig interface{}) error {
			if err != nil {
				return err
			}
			return FromFile(configFile, baseConfig)
		},
	}
}
770558
func (m *Meta) loadConfig(rootDir string) (*configs.Config, tfdiags.Diagnostics) {
	var diags tfdiags.Diagnostics
	rootDir = m.normalizePath(rootDir)

	loader, err := m.initConfigLoader()
	if err != nil {
		diags = diags.Append(err)
		return nil, diags
	}

	config, hclDiags := loader.LoadConfig(rootDir)
	diags = diags.Append(hclDiags)
	return config, diags
}
204564
func (p *Parser) IsConfigDir(path string) bool {
	primaryPaths, overridePaths, _ := p.dirFiles(path)
	return (len(primaryPaths) + len(overridePaths)) > 0
}
949470
func LoadConfig(configPath string) (types.Config, error) {
	config := types.Config{}

	bytes, err := ioutil.ReadFile(configPath)
	if err != nil {
		return config, err
	}

	if err := yaml.Unmarshal(bytes, &config); err != nil {
		return config, err
	}

	if config.LockTimeout == 0 {
		config.LockTimeout = defaultTTL
	}

	if config.GlobalTimeout == 0 {
		log.Fatal("[Config] Global timeout invaild, exit")
	}
	config.GlobalTimeout = config.GlobalTimeout * time.Second

	if config.Etcd.Prefix == "" {
		config.Etcd.Prefix = defaultPrefix
	}

	if config.Docker.APIVersion == "" {
		config.Docker.APIVersion = "1.32"
	}
	// 默认是 journald
	if config.Docker.Log.Type == "" {
		config.Docker.Log.Type = "journald"
	}
	if config.Scheduler.ShareBase == 0 {
		config.Scheduler.ShareBase = 100
	}
	if config.Scheduler.MaxShare == 0 {
		config.Scheduler.MaxShare = -1
	}

	return config, nil
}
996040
func LoadConfig() (*AppConfig, error) {
	var (
		conf AppConfig
		err  error
	)
	err = envconfig.Process("digota", &conf)
	if err != nil {
		return nil, err
	}
	return &conf, nil
}
645708
func (t *Repository) LoadDir(templatePath string) error {
	err := filepath.Walk(templatePath, func(path string, info os.FileInfo, err error) error {

		if strings.HasSuffix(path, ".gotmpl") {
			if assetName, e := filepath.Rel(templatePath, path); e == nil {
				if data, e := ioutil.ReadFile(path); e == nil {
					if ee := t.AddFile(assetName, string(data)); ee != nil {
						// Fatality is decided by caller
						// log.Fatal(ee)
						return fmt.Errorf("Could not add template: %v", ee)
					}
				}
				// Non-readable files are skipped
			}
		}
		if err != nil {
			return err
		}
		// Non-template files are skipped
		return nil
	})
	if err != nil {
		return fmt.Errorf("Could not complete template processing in directory \"%s\": %v", templatePath, err)
	}
	return nil
}