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
|
LOG_LEVEL=INFO
|
||||||
|
|
||||||
DATABASE_URL_FILE=/run/secrets/database_url
|
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
|
CACHE_URL_FILE=/run/secrets/cache_url
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ services:
|
|||||||
- .env
|
- .env
|
||||||
secrets:
|
secrets:
|
||||||
- database_url
|
- database_url
|
||||||
|
- cache_url
|
||||||
depends_on:
|
depends_on:
|
||||||
migrate:
|
migrate:
|
||||||
condition: service_completed_successfully
|
condition: service_completed_successfully
|
||||||
@@ -62,6 +63,8 @@ secrets:
|
|||||||
file: ./secrets/postgres_password.txt
|
file: ./secrets/postgres_password.txt
|
||||||
database_url:
|
database_url:
|
||||||
file: ./secrets/database_url.txt
|
file: ./secrets/database_url.txt
|
||||||
|
cache_url:
|
||||||
|
file: ./secrets/cache_url.txt
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
pgdata:
|
pgdata:
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ type Config struct {
|
|||||||
Server ServerConfig
|
Server ServerConfig
|
||||||
Logging LoggingConfig
|
Logging LoggingConfig
|
||||||
Database DatabaseConfig
|
Database DatabaseConfig
|
||||||
|
Redis RedisConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
type ServerConfig struct {
|
type ServerConfig struct {
|
||||||
@@ -35,6 +36,14 @@ func (c DatabaseConfig) URL() (string, error) {
|
|||||||
return readSecretFile(c.URLFile)
|
return readSecretFile(c.URLFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RedisConfig struct {
|
||||||
|
URLFile string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c RedisConfig) URL() (string, error) {
|
||||||
|
return readSecretFile(c.URLFile)
|
||||||
|
}
|
||||||
|
|
||||||
func Load() Config {
|
func Load() Config {
|
||||||
return Config{
|
return Config{
|
||||||
Server: ServerConfig{
|
Server: ServerConfig{
|
||||||
@@ -51,6 +60,10 @@ func Load() Config {
|
|||||||
Database: DatabaseConfig{
|
Database: DatabaseConfig{
|
||||||
URLFile: getEnv("DATABASE_URL_FILE", "/run/secrets/database_url"),
|
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