koanf icon indicating copy to clipboard operation
koanf copied to clipboard

feature: search file

Open bersace opened this issue 1 year ago • 1 comments

Hi,

Thanks for koanf, it's awesome.

I think it may be useful if file module provides a helper to find a file amongst candidate. e.g.

path := file.Find(
    "ldaprc",
    ".ldaprc",
    "ldap.conf",
)

And also finding a file in parent directory:

path := file.FindParent("docker-compose.yml")

What do you think of this need ?

Regards, Étienne

bersace avatar May 06 '24 13:05 bersace

Thanks @bersace. Unsure if we should add these as util functions as they only take a couple of lines of code to implement. In the same vein, there may be many other niche util functions that'll then have to be considered. FindRecursively() etc.

Implementing a Find functionality can be as simple as this for instance.

	for _, f := range []string{"ldaprc", ".ldaprc", "ldap.conf"} {
		if _, err := os.Stat(filename); err == nil {
			k.Load(file.Provider(f), toml.Parser())
			break
		}
	}

knadh avatar May 07 '24 05:05 knadh