diff options
| author | haturatu <taro@eyes4you.org> | 2025-10-12 17:04:07 +0900 |
|---|---|---|
| committer | haturatu <taro@eyes4you.org> | 2025-10-12 17:04:07 +0900 |
| commit | 957dc75eddf69ccf26bd387828b9e205a5425f30 (patch) | |
| tree | 15a3f5581dded804a383c1d42e5b7d4b967da11e /config | |
| parent | 10c90d8654b94916bf0a4ffb8263e512a8e6be04 (diff) | |
add(api): api endpoint authorized Bearer token
Diffstat (limited to 'config')
| -rw-r--r-- | config/config.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/config/config.go b/config/config.go index 35cd2dc..236ed41 100644 --- a/config/config.go +++ b/config/config.go @@ -3,6 +3,9 @@ package config import ( "auth-proxy/types" "os" + "strconv" + + "github.com/joho/godotenv" ) // Paths holds the global configuration values. @@ -16,8 +19,21 @@ func getEnv(key, fallback string) string { return fallback } +// getEnvAsBool reads an environment variable as a boolean or returns a fallback value. +func getEnvAsBool(key string, fallback bool) bool { + if value, ok := os.LookupEnv(key); ok { + if b, err := strconv.ParseBool(value); err == nil { + return b + } + } + return fallback +} + // Init loads path configurations from environment variables. func Init() { + // Load .env file. Errors are ignored, so variables from the environment can still be used. + _ = godotenv.Load() + Paths = types.PathConfig{ Login: getEnv("AUTH_PATH_LOGIN", "/login"), Register: getEnv("AUTH_PATH_REGISTER", "/register"), @@ -27,5 +43,9 @@ func Init() { Admin: getEnv("AUTH_PATH_ADMIN", "/admin"), AdminUsersAPI: getEnv("AUTH_PATH_ADMIN_USERS_API", "/api/admin/users"), Assets: getEnv("AUTH_ASSETS_PATH", "/auth-proxy-assets"), + ProtectFrontend: getEnvAsBool("PROTECT_FRONTEND", false), + ProtectAPI: getEnvAsBool("PROTECT_API", false), + FrontPath: getEnv("FRONT_PATH", "/"), + APIPath: getEnv("API_PATH", "/api/"), } } |
