forked from baron/baron-sso
fix: 환경변수 내 큰따옴표(")로 인한 URL 파싱 에러 수정 (utils.GetEnv 도입) #239
This commit is contained in:
22
backend/internal/utils/env.go
Normal file
22
backend/internal/utils/env.go
Normal file
@@ -0,0 +1,22 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user