feat(sol): UDP + HTTP listener
This commit is contained in:
50
utils/env.go
Normal file
50
utils/env.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"git.secnex.io/secnex/masterlog"
|
||||
)
|
||||
|
||||
func GetEnv(key string, defaultValue string) string {
|
||||
value := os.Getenv(key)
|
||||
if value == "" {
|
||||
return defaultValue
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func GetStringFromEnv(key string, defaultValue string) string {
|
||||
return GetEnv(key, defaultValue)
|
||||
}
|
||||
|
||||
func GetIntFromEnv(key string, defaultValue int) int {
|
||||
value := os.Getenv(key)
|
||||
if value == "" {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
intValue, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
return defaultValue
|
||||
}
|
||||
return intValue
|
||||
}
|
||||
|
||||
func GetBoolFromEnv(key string, defaultValue bool) bool {
|
||||
value := os.Getenv(key)
|
||||
if value == "" {
|
||||
return defaultValue
|
||||
}
|
||||
if value == "true" || value == "TRUE" || value == "True" || value == "1" {
|
||||
return true
|
||||
} else {
|
||||
masterlog.Error("Invalid environment variable value", map[string]interface{}{
|
||||
"variable": key,
|
||||
"value": value,
|
||||
"type": "boolean",
|
||||
})
|
||||
return false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user