Skip to content

Commit e604aa5

Browse files
Copilotlpcox
andcommitted
Complete refactoring of duplicate environment variable getters
All tests pass including make agent-finished verification Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
1 parent 8fe4967 commit e604aa5

2 files changed

Lines changed: 424 additions & 424 deletions

File tree

internal/envutil/envutil.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
package envutil
22

33
import (
4-
"os"
5-
"strconv"
6-
"strings"
4+
"os"
5+
"strconv"
6+
"strings"
77
)
88

99
// GetEnvString returns the value of the environment variable specified by envKey.
1010
// If the environment variable is not set or is empty, it returns the defaultValue.
1111
func GetEnvString(envKey, defaultValue string) string {
12-
if value := os.Getenv(envKey); value != "" {
13-
return value
14-
}
15-
return defaultValue
12+
if value := os.Getenv(envKey); value != "" {
13+
return value
14+
}
15+
return defaultValue
1616
}
1717

1818
// GetEnvInt returns the integer value of the environment variable specified by envKey.
1919
// If the environment variable is not set, is empty, cannot be parsed as an integer,
2020
// or is not positive (> 0), it returns the defaultValue.
2121
// This function validates that the value is a positive integer.
2222
func GetEnvInt(envKey string, defaultValue int) int {
23-
if envValue := os.Getenv(envKey); envValue != "" {
24-
if value, err := strconv.Atoi(envValue); err == nil && value > 0 {
25-
return value
26-
}
27-
}
28-
return defaultValue
23+
if envValue := os.Getenv(envKey); envValue != "" {
24+
if value, err := strconv.Atoi(envValue); err == nil && value > 0 {
25+
return value
26+
}
27+
}
28+
return defaultValue
2929
}
3030

3131
// GetEnvBool returns the boolean value of the environment variable specified by envKey.
@@ -34,13 +34,13 @@ return defaultValue
3434
// Falsy values (case-insensitive): "0", "false", "no", "off"
3535
// Any other value returns the defaultValue.
3636
func GetEnvBool(envKey string, defaultValue bool) bool {
37-
if envValue := os.Getenv(envKey); envValue != "" {
38-
switch strings.ToLower(envValue) {
39-
case "1", "true", "yes", "on":
40-
return true
41-
case "0", "false", "no", "off":
42-
return false
43-
}
44-
}
45-
return defaultValue
37+
if envValue := os.Getenv(envKey); envValue != "" {
38+
switch strings.ToLower(envValue) {
39+
case "1", "true", "yes", "on":
40+
return true
41+
case "0", "false", "no", "off":
42+
return false
43+
}
44+
}
45+
return defaultValue
4646
}

0 commit comments

Comments
 (0)