feat(auth): make session cache optional via SESSION_STORE

This commit is contained in:
kk10
2026-10-16 21:18:17 +03:00
parent 6e0829e628
commit cd6a1c7aee
4 changed files with 105 additions and 39 deletions
+30 -4
View File
@@ -10,11 +10,21 @@ import (
"time"
)
const (
SessionStorePostgres = "postgres"
SessionStoreRedis = "redis"
)
type Config struct {
Server ServerConfig
Logging LoggingConfig
Database DatabaseConfig
Redis RedisConfig
Server ServerConfig
Logging LoggingConfig
Database DatabaseConfig
Redis RedisConfig
SessionStore string
}
func (c Config) UseCache() bool {
return c.SessionStore == SessionStoreRedis
}
type ServerConfig struct {
@@ -64,6 +74,8 @@ func Load() Config {
Redis: RedisConfig{
URLFile: getEnv("CACHE_URL_FILE", "/run/secrets/cache_url"),
},
SessionStore: getEnvSessionStore("SESSION_STORE", SessionStorePostgres),
}
}
@@ -139,3 +151,17 @@ func readSecretFile(path string) (string, error) {
return value, nil
}
func getEnvSessionStore(key, def string) string {
v := strings.ToLower(os.Getenv(key))
switch v {
case "":
return def
case SessionStorePostgres, SessionStoreRedis:
return v
default:
log.Printf("invalid session store for %s=%q, using default %s", key, v, def)
return def
}
}