Skip to content

Commit 4cbc8fe

Browse files
dieselburnerlimdingwen
authored andcommitted
Avoid double calls of os.Getenv()
1 parent 89d3ef9 commit 4cbc8fe

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/settings.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,18 @@ func (settings *Settings) boolFlagEnv(p *bool, name string, env string, value bo
5858

5959
func (settings *Settings) int64FlagEnv(p *int64, name string, env string, value int64, usage string) {
6060
flag.Int64Var(p, name, value, usage+" (env "+env+")")
61-
if os.Getenv(env) != "" {
62-
i, _ := strconv.ParseInt(os.Getenv(env), 10, 0)
61+
val := os.Getenv(env)
62+
if val != "" {
63+
i, _ := strconv.ParseInt(val, 10, 0)
6364
*p = i
6465
}
6566
}
6667

6768
func (settings *Settings) stringFlagEnv(p *string, name string, env string, value string, usage string) {
6869
flag.StringVar(p, name, value, usage+" (env "+env+")")
69-
if os.Getenv(env) != "" {
70-
*p = os.Getenv(env)
70+
val := os.Getenv(env)
71+
if val != "" {
72+
*p = val
7173
}
7274
}
7375

0 commit comments

Comments
 (0)