mirror of
https://github.com/Xevion/banner.git
synced 2025-12-09 14:06:34 -06:00
Fix private URL var name, add helper for retrieving various environment variables
This commit is contained in:
10
helpers.go
10
helpers.go
@@ -5,6 +5,7 @@ import (
|
||||
"io"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"os"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -177,3 +178,12 @@ func (nt NaiveTime) String() string {
|
||||
}
|
||||
return fmt.Sprintf("%d:%02d%s", hour, nt.Minutes, meridiem)
|
||||
}
|
||||
|
||||
func GetFirstEnv(key ...string) string {
|
||||
for _, k := range key {
|
||||
if v := os.Getenv(k); v != "" {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
16
main.go
16
main.go
@@ -59,12 +59,9 @@ func init() {
|
||||
ctx = context.Background()
|
||||
|
||||
// Try to grab the environment variable, or default to development
|
||||
env := os.Getenv("ENVIRONMENT")
|
||||
env := GetFirstEnv("ENVIRONMENT", "RAILWAY_ENVIRONMENT")
|
||||
if env == "" {
|
||||
env = os.Getenv("RAILWAY_ENVIRONMENT")
|
||||
if env == "" {
|
||||
env = "development"
|
||||
}
|
||||
env = "development"
|
||||
}
|
||||
|
||||
// Use the custom console writer if we're in development
|
||||
@@ -85,13 +82,12 @@ func init() {
|
||||
|
||||
func main() {
|
||||
// Setup redis
|
||||
redisUrl := os.Getenv("REDIS_URL")
|
||||
redisUrl := GetFirstEnv("REDIS_URL", "REDIS_PRIVATE_URL")
|
||||
if redisUrl == "" {
|
||||
redisUrl = os.Getenv("PRIVATE_REDIS_URL")
|
||||
if redisUrl == "" {
|
||||
log.Fatal().Msg("REDIS_URL is not set (public or private)")
|
||||
}
|
||||
log.Fatal().Msg("REDIS_URL/REDIS_PRIVATE_URL not set")
|
||||
}
|
||||
|
||||
// Parse URL and create client
|
||||
options, err := redis.ParseURL(redisUrl)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("Cannot parse redis url")
|
||||
|
||||
Reference in New Issue
Block a user