-
-
Notifications
You must be signed in to change notification settings - Fork 520
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
Expand env vars and flags #84
Conversation
main.go
Outdated
func LookupEnvOrString(key string, defaultVal string) string { | ||
if val, ok := os.LookupEnv(key); ok { | ||
return val | ||
} | ||
return defaultVal | ||
} | ||
|
||
func LookupEnvOrBool(key string, defaultVal bool) bool { | ||
if val, ok := os.LookupEnv(key); ok { | ||
v, err := strconv.ParseBool(val) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "LookupEnvOrInt[%s]: %v\n", key, err) | ||
} | ||
return v | ||
} | ||
return defaultVal | ||
} | ||
|
||
func LookupEnvOrInt(key string, defaultVal int) int { | ||
if val, ok := os.LookupEnv(key); ok { | ||
v, err := strconv.Atoi(val) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "LookupEnvOrInt[%s]: %v\n", key, err) | ||
} | ||
return v | ||
} | ||
return defaultVal | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move these functions to util/util.go
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I can. But I think it would be better if you reject this PR, and I rewrote it using the viper library. https://github.com/spf13/viper
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, I don't know. To me, it looks like using viper is an overkill solution for this purpose. I would prefer simple ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem. Lets stick to the original plan. I'll move the functions to util.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes made and smoke tested. If I werent so lazy, I would write some real tests.
I wanted to be able to set configurations from environment vars or flags. This should allow more flexibility in the future.