-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Support env in mysql Signed-off-by: Ce Gao <gaoce@caicloud.io> * fix: Reuse code Signed-off-by: Ce Gao <gaoce@caicloud.io>
- Loading branch information
1 parent
cefb6fe
commit 89ed82b
Showing
5 changed files
with
46 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package env | ||
|
||
import "os" | ||
|
||
func GetEnvOrDefault(key string, fallback string) string { | ||
if value, ok := os.LookupEnv(key); ok { | ||
return value | ||
} | ||
return fallback | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package env | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestGetEnvWithDefault(t *testing.T) { | ||
expected := "FAKE" | ||
key := "TEST" | ||
v := GetEnvOrDefault(key, expected) | ||
if v != expected { | ||
t.Errorf("Expected %s, got %s", expected, v) | ||
} | ||
expected = "FAKE1" | ||
os.Setenv(key, expected) | ||
v = GetEnvOrDefault(key, "") | ||
if v != expected { | ||
t.Errorf("Expected %s, got %s", expected, v) | ||
} | ||
} |