Skip to content

Commit

Permalink
update: remove the generic EnvOrDefault, string by default
Browse files Browse the repository at this point in the history
  • Loading branch information
kgrodzicki committed May 19, 2023
1 parent 2087de9 commit 0a6d1ae
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 17 deletions.
11 changes: 1 addition & 10 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,7 @@ import (
)

// EnvOrDefault returns the value of the environment variable k or defaultVal if it is not set.
func EnvOrDefault(k string, defaultVal interface{}) interface{} {
v := os.Getenv(k)
if v == "" {
return defaultVal
}
return v
}

// EnvOrDefaultString returns the value of the environment variable k or defaultVal if it is not set.
func EnvOrDefaultString(k string, defaultVal string) string {
func EnvOrDefault(k string, defaultVal string) string {
v := os.Getenv(k)
if v == "" {
return defaultVal
Expand Down
7 changes: 0 additions & 7 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ func TestUtils(t *testing.T) {
assert.Equal(t, "DEFAULT_VALUE2", EnvOrDefault("TEST_KEY2", "DEFAULT_VALUE2"))
})

t.Run("EnvOrDefaultString", func(t *testing.T) {
assert.Equal(t, "test", EnvOrDefaultString("NOT_EXISTING", "test"))
err := os.Setenv("TEST_KEY", "apud")
assert.Nil(t, err)
assert.Equal(t, "apud", EnvOrDefaultString("TEST_KEY", "test"))
})

t.Run("EnvOrDefaultInt64", func(t *testing.T) {
assert.Equal(t, int64(4321), EnvOrDefaultInt64("NOT_EXISTING", 4321))
err := os.Setenv("TEST_KEY", "1234")
Expand Down

0 comments on commit 0a6d1ae

Please sign in to comment.