-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix some errors in nacosREST (#54)
1. Skip the __names__ item when enumerating all configs 2. Allow changing some Nacos options via environment variables 3. Use local Nacos config cache as a fallback by default
- Loading branch information
Showing
3 changed files
with
73 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package utils | ||
|
||
import ( | ||
"os" | ||
"strconv" | ||
) | ||
|
||
func GetStringFromEnv(key, defaultValue string) string { | ||
if len(key) == 0 { | ||
return defaultValue | ||
} | ||
value := os.Getenv(key) | ||
if len(value) != 0 { | ||
return value | ||
} | ||
return defaultValue | ||
} | ||
|
||
func GetIntFromEnv(key string, defaultValue int) int { | ||
strValue := GetStringFromEnv(key, "") | ||
if len(strValue) == 0 { | ||
return defaultValue | ||
} | ||
if value, err := strconv.Atoi(strValue); err != nil { | ||
return defaultValue | ||
} else { | ||
return value | ||
} | ||
} | ||
|
||
func GetBoolFromEnv(key string, defaultValue bool) bool { | ||
strValue := GetStringFromEnv(key, "") | ||
if len(strValue) == 0 { | ||
return defaultValue | ||
} | ||
if value, err := strconv.ParseBool(strValue); err != nil { | ||
return defaultValue | ||
} else { | ||
return value | ||
} | ||
} |