Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: search file #293

Open
bersace opened this issue May 6, 2024 · 1 comment
Open

feature: search file #293

bersace opened this issue May 6, 2024 · 1 comment
Labels
question Further information is requested

Comments

@bersace
Copy link

bersace commented May 6, 2024

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

@knadh
Copy link
Owner

knadh commented May 7, 2024

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 knadh added the question Further information is requested label May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants