Closed rossmcf closed 5 years ago
PR submitted. Suggestions welcome.
I don't understand the requirement. If you want to protect against forgetting to add the environment variables in production, can't you simply mark the fields as required
?
@CAFxX We do that, but the issue we have is that we have to start up the service with each environment's config file in order to see the missing values. And in some cases we'd rather not start a service with production config, as it might start consuming from queues, for example.
Wouldn't having a dry-run/config validation flag that instructs the process to exit immediately after parsing its configuration be the simple and easy solution, then?
func main() {
cfg := &Config{}
if err := envconfig.Parse(cfg); err != nil {
// Fatal(err)
}
// perform here any additional config validation, erroring out if it fails...
if cfg.DryRun {
os.Exit(0)
}
// actual program logic...
}
Alternatively, why can't you produce a parseable dump of the list of known envvars using Usagef
/Usaget
, and then use it during your build process to validate whatever preconditions have to be met for a successful build?
I had some feedback on the PR, but @CAFxX you're way ahead of me here. Great suggestions, thank you.
I work in a team that uses docker-compose. Commonly, we have docker-compose.yml files for each of our environments. It's a fairly common issue that we define new environment variables for a service, but forget to include them in the production environment's compose file, since it doesn't tend to be used locally.
I don't propose to make envconfig aware of docker compose, but I would like a way to 'check' an arbitrary set of keys/values against a spec. I can put together a tool to get the environment variables from the docker-compose file, but I can't currently pass those in to envconfig. Would you be open to adding a
Check(prefix string, spec interface{}, kvs map[string]string)
method? I'd be happy to submit a PR for it.