forked from mtusi2026/mtusi2026lab2
feat(config): add redis url secret
This commit is contained in:
+1
-2
@@ -6,6 +6,5 @@ SESSION_TTL_SECONDS=3600
|
||||
LOG_LEVEL=INFO
|
||||
|
||||
DATABASE_URL_FILE=/run/secrets/database_url
|
||||
# Optional on 3, required use on 4 in lab2; Redis OR Valkey:
|
||||
SESSION_STORE=postgres
|
||||
|
||||
CACHE_URL_FILE=/run/secrets/cache_url
|
||||
|
||||
@@ -10,6 +10,7 @@ services:
|
||||
- .env
|
||||
secrets:
|
||||
- database_url
|
||||
- cache_url
|
||||
depends_on:
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
@@ -62,6 +63,8 @@ secrets:
|
||||
file: ./secrets/postgres_password.txt
|
||||
database_url:
|
||||
file: ./secrets/database_url.txt
|
||||
cache_url:
|
||||
file: ./secrets/cache_url.txt
|
||||
|
||||
volumes:
|
||||
pgdata:
|
||||
|
||||
@@ -14,6 +14,7 @@ type Config struct {
|
||||
Server ServerConfig
|
||||
Logging LoggingConfig
|
||||
Database DatabaseConfig
|
||||
Redis RedisConfig
|
||||
}
|
||||
|
||||
type ServerConfig struct {
|
||||
@@ -35,6 +36,14 @@ func (c DatabaseConfig) URL() (string, error) {
|
||||
return readSecretFile(c.URLFile)
|
||||
}
|
||||
|
||||
type RedisConfig struct {
|
||||
URLFile string
|
||||
}
|
||||
|
||||
func (c RedisConfig) URL() (string, error) {
|
||||
return readSecretFile(c.URLFile)
|
||||
}
|
||||
|
||||
func Load() Config {
|
||||
return Config{
|
||||
Server: ServerConfig{
|
||||
@@ -51,6 +60,10 @@ func Load() Config {
|
||||
Database: DatabaseConfig{
|
||||
URLFile: getEnv("DATABASE_URL_FILE", "/run/secrets/database_url"),
|
||||
},
|
||||
|
||||
Redis: RedisConfig{
|
||||
URLFile: getEnv("CACHE_URL_FILE", "/run/secrets/cache_url"),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
package redis
|
||||
Reference in New Issue
Block a user