Documentation
¶
Overview ¶
Package findcfg finds a config file.
// finder for a YAML file in os.Executable() and os.UserConfigDir()+myapp
finder := findcfg.New(
findcfg.YAML(),
findcfg.ExecutableDir(),
findcfg.UserConfigDir("myapp"),
)
found := finder.Find("config") // config.yaml
if found != nil {
return found.Path
}
return finder.FallbackPath(configName)
Index ¶
- type DirFunc
- type Finder
- type FinderOption
- func CurrentDir(sub ...string) FinderOption
- func Dir(sub ...string) FinderOption
- func ExactPath(exact string) FinderOption
- func ExecutableDir(sub ...string) FinderOption
- func Ext(exts ...string) FinderOption
- func HomeDir(sub ...string) FinderOption
- func INI() FinderOption
- func JSON() FinderOption
- func Name(names string) FinderOption
- func TOML() FinderOption
- func UserConfigDir(sub ...string) FinderOption
- func YAML() FinderOption
- type Found
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Finder ¶
type Finder struct {
Exts []string
Names []string
Dirs []DirFunc
Exacts []string // absolute file path
}
func New ¶
func New(opts ...FinderOption) *Finder
New returns a Finder with given options.
see FinderOption.
func (*Finder) AddDirs ¶
AddDirs adds search paths. If no dirs given by AddDirs and New, the Finder does not find anything.
func (*Finder) AddExts ¶
AddExts adds extentions. (needs a period like ".yaml") If no exts given by AddExts and New, the Finder does not find anything.
func (*Finder) FallbackPath ¶
FallbackPath returns a path that may not be exist. Call this method if Find does not find anything.
This method returns the firstly tried path.
type FinderOption ¶
type FinderOption func(*Finder)