51 lines
942 B
Go
51 lines
942 B
Go
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
|
|
}
|
|
}
|