Skip to content

Commit

Permalink
feat(int): allow REDIS_URL as alais for CACHE_DSN
Browse files Browse the repository at this point in the history
Refs: #119
  • Loading branch information
pascal-zarrad committed Mar 3, 2023
1 parent f1fbf31 commit 2454079
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion internal/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const (
sqlUrl = "DATABASE_URL"
cacheMode = "CACHE_MODE"
cacheDsn = "CACHE_DSN"
redisUrl = "REDIS_URL"
webApiMode = "WEBAPI_MODE"
webApiBind = "WEBAPI_BIND"
webApiHost = "WEBAPI_HOST"
Expand Down Expand Up @@ -115,7 +116,7 @@ func initEnv() {
sqlMode: getEnvOrFail(sqlMode),
sqlUrl: getEnvOrDefault(sqlUrl, ""),
cacheMode: cache.Mode(getEnvOrFail(cacheMode)),
cacheDsn: cache.Dsn(getEnvOrDefault(cacheDsn, "")),
cacheDsn: findCacheDsn(),
webApiMode: getEnvOrDefault(webApiMode, DefaultWebApiMode),
webApiBind: getEnvOrDefault(webApiBind, DefaultWebApiBind),
webApiHost: getEnvOrDefault(webApiHost, DefaultWebApiHost),
Expand All @@ -124,3 +125,16 @@ func initEnv() {
}
coreLogger.Info("Successfully loaded environment configuration!")
}

// findCacheDsn returns the configured cache DSN for the application.
// The function allows the use of aliases as REDIS_URL for the CACHE_DSN variable.
// The function will return on the first found valid alias.
// When no alias is set, the CACHE_DSN variable will be used by default.
func findCacheDsn() cache.Dsn {
redisUrl := getEnvOrDefault(redisUrl, "")
if "" != redisUrl {
return cache.Dsn(redisUrl)
}

return cache.Dsn(getEnvOrDefault(cacheDsn, ""))
}

0 comments on commit 2454079

Please sign in to comment.