forked from baron/baron-sso
23 lines
535 B
Go
23 lines
535 B
Go
package utils
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
// GetEnv retrieves the value of the environment variable named by the key.
|
|
// It returns the value if it exists, otherwise it returns the fallback value.
|
|
// It automatically strips surrounding double quotes from the value.
|
|
func GetEnv(key, fallback string) string {
|
|
v := os.Getenv(key)
|
|
if v == "" {
|
|
return fallback
|
|
}
|
|
// Strip surrounding double quotes if present
|
|
v = strings.TrimSpace(v)
|
|
if len(v) >= 2 && v[0] == '"' && v[len(v)-1] == '"' {
|
|
return v[1 : len(v)-1]
|
|
}
|
|
return v
|
|
}
|