-
Notifications
You must be signed in to change notification settings - Fork 177
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
configFileNotFound bug? #141
Comments
@ghostsquad I was just looking at this too, and it is correct, just hard to read. If you switch the order of the If you want to avoid the error, change it to this (with explanatory comments added):
(That is what I did) |
Admittedly, this kind of assertion is always hard to read, especially with errors (or pointers in generic). Whether warning is a correct level for a missing config file or not depends on how you operate your applications: most of the time I deploy them to Kubernetes using Helm, so YAML comes as a first class citizen in Helm values, translated into a config file. But that's just how I do things, I don't consider it a best practice. If you strictly want to follow Twelve Factor apps, using env vars is perfectly fine. I can think of two possible improvements (not touching the assertion though):
One could also argue that this is actually not really relevant during normal operations and only has a value during debugging, so we could make it a debug log as well. WDYT? |
There is one production case in which it makes sense to be a warning (or maybe even an error). I am considering the following four cases:
|
I was just reviewing the code, and I found a part that looks a little suspect..
https://github.com/sagikazarmark/modern-go-application/blob/master/cmd/modern-go-application/main.go?ts=4#L89
if
ReadInConfig
does not return an error, thenconfigFileNotFound
would be false, right? since the type assert fromnil
toviper.ConfigFileNotFoundError
would fail?it seems like the code will either always panic, or log a warning.
The viper shows the correct way: https://github.com/spf13/viper?ts=4#reading-config-files
Additionally, I don't think this is best practice anyway, since a configuration file should not be required if ENV variables are also an alternative. Maybe I'm also reading the code wrong...
The text was updated successfully, but these errors were encountered: