Open Aquarthur opened 8 months ago
Provide an interface for the user to pass in an fs.FS alongside a filename.
fs.FS
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.
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 { ... }
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: