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

Allow reading from fs.FS #135

Open
Aquarthur opened this issue Jan 7, 2024 · 0 comments
Open

Allow reading from fs.FS #135

Aquarthur opened this issue Jan 7, 2024 · 0 comments

Comments

@Aquarthur
Copy link

Provide an interface for the user to pass in an fs.FS alongside a filename.

This will add some flexibility about how the file is loaded, and makes it easier for users to write tests to verify configs via testing/fstest.

Something like:

type ConfigDatabase struct {
	Port     string `yaml:"port" env:"PORT" env-default:"5432"`
	Host     string `yaml:"host" env:"HOST" env-default:"localhost"`
	Name     string `yaml:"name" env:"NAME" env-default:"postgres"`
	User     string `yaml:"user" env:"USER" env-default:"user"`
	Password string `yaml:"password" env:"PASSWORD"`
}

var cfg ConfigDatabase

fsys := os.DirFS("/example/config/folder")
err := cleanenv.ReadConfigFS(fsys, "config.yml", &cfg)
if err != nil {
	...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant