func FromPath(path string) (*Config, error) {
	// Ensure the given filepath exists
	if _, err := os.Stat(path); os.IsNotExist(err) {
		return nil, errors.Wrap(err, "missing file/folder: "+path)
	}

	// Check if a file was given or a path to a directory
	stat, err := os.Stat(path)
	if err != nil {
		return nil, errors.Wrap(err, "failed stating file: "+path)
	}

	// Recursively parse directories, single load files
	if stat.Mode().IsDir() {
		// Ensure the given filepath has at least one config file
		_, err := ioutil.ReadDir(path)
		if err != nil {
			return nil, errors.Wrap(err, "failed listing dir: "+path)
		}

		// Create a blank config to merge off of
		var c *Config

		// Potential bug: Walk does not follow symlinks!
		err = filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
			// If WalkFunc had an error, just return it
			if err != nil {
				return err
			}

			// Do nothing for directories
			if info.IsDir() {
				return nil
			}

			// Parse and merge the config
			newConfig, err := FromFile(path)
			if err != nil {
				return err
			}
			c = c.Merge(newConfig)

			return nil
		})

		if err != nil {
			return nil, errors.Wrap(err, "walk error")
		}

		return c, nil
	} else if stat.Mode().IsRegular() {
		return FromFile(path)
	}

	return nil, fmt.Errorf("unknown filetype: %q", stat.Mode().String())
}
func FromPath(path string) (*Config, error) {
	// Ensure the given filepath exists
	if _, err := os.Stat(path); os.IsNotExist(err) {
		return nil, errors.Wrap(err, "missing file/folder: "+path)
	}

	// Check if a file was given or a path to a directory
	stat, err := os.Stat(path)
	if err != nil {
		return nil, errors.Wrap(err, "failed stating file: "+path)
	}

	// Recursively parse directories, single load files
	if stat.Mode().IsDir() {
		// Ensure the given filepath has at least one config file
		_, err := ioutil.ReadDir(path)
		if err != nil {
			return nil, errors.Wrap(err, "failed listing dir: "+path)
		}

		// Create a blank config to merge off of
		var c *Config

		// Potential bug: Walk does not follow symlinks!
		err = filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
			// If WalkFunc had an error, just return it
			if err != nil {
				return err
			}

			// Do nothing for directories
			if info.IsDir() {
				return nil
			}

			// Parse and merge the config
			newConfig, err := FromFile(path)
			if err != nil {
				return err
			}
			c = c.Merge(newConfig)

			return nil
		})

		if err != nil {
			return nil, errors.Wrap(err, "walk error")
		}

		return c, nil
	} else if stat.Mode().IsRegular() {
		return FromFile(path)
	}

	return nil, fmt.Errorf("unknown filetype: %q", stat.Mode().String())
}
func FromPath ( path string ) ( * Config , error ) { // Ensure the given filepath exists if _ , err := os . Stat ( path ) ; os . IsNotExist ( err ) { return nil , errors . Wrap ( err , " " + path ) } // Check if a file was given or a path to a directory stat , err := os . Stat ( path ) if err != nil { return nil , errors . Wrap ( err , " " + path ) } // Recursively parse directories, single load files if stat . Mode ( ) . IsDir ( ) { // Ensure the given filepath has at least one config file _ , err := ioutil . ReadDir ( path ) if err != nil { return nil , errors . Wrap ( err , " " + path ) } // Create a blank config to merge off of var c * Config // Potential bug: Walk does not follow symlinks! err = filepath . Walk ( path , func ( path string , info os . FileInfo , err error ) error { // If WalkFunc had an error, just return it if err != nil { return err } // Do nothing for directories if info . IsDir ( ) { return nil } // Parse and merge the config newConfig , err := FromFile ( path ) if err != nil { return err } c = c . Merge ( newConfig ) return nil } ) if err != nil { return nil , errors . Wrap ( err , " " ) } return c , nil } else if stat . Mode ( ) . IsRegular ( ) { return FromFile ( path ) } return nil , fmt . Errorf ( " " , stat . Mode ( ) . String ( ) ) }
// FromPath iterates and merges all configuration files in a given
// directory, returning the resulting config.
FromPath iterates and merges all configuration files in a given directory returning the resulting config .