mirror of
https://github.com/Xevion/banner.git
synced 2025-12-11 10:06:36 -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"
|
"io"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -177,3 +178,12 @@ func (nt NaiveTime) String() string {
|
|||||||
}
|
}
|
||||||
return fmt.Sprintf("%d:%02d%s", hour, nt.Minutes, meridiem)
|
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()
|
ctx = context.Background()
|
||||||
|
|
||||||
// Try to grab the environment variable, or default to development
|
// Try to grab the environment variable, or default to development
|
||||||
env := os.Getenv("ENVIRONMENT")
|
env := GetFirstEnv("ENVIRONMENT", "RAILWAY_ENVIRONMENT")
|
||||||
if env == "" {
|
if env == "" {
|
||||||
env = os.Getenv("RAILWAY_ENVIRONMENT")
|
env = "development"
|
||||||
if env == "" {
|
|
||||||
env = "development"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use the custom console writer if we're in development
|
// Use the custom console writer if we're in development
|
||||||
@@ -85,13 +82,12 @@ func init() {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Setup redis
|
// Setup redis
|
||||||
redisUrl := os.Getenv("REDIS_URL")
|
redisUrl := GetFirstEnv("REDIS_URL", "REDIS_PRIVATE_URL")
|
||||||
if redisUrl == "" {
|
if redisUrl == "" {
|
||||||
redisUrl = os.Getenv("PRIVATE_REDIS_URL")
|
log.Fatal().Msg("REDIS_URL/REDIS_PRIVATE_URL not set")
|
||||||
if redisUrl == "" {
|
|
||||||
log.Fatal().Msg("REDIS_URL is not set (public or private)")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse URL and create client
|
||||||
options, err := redis.ParseURL(redisUrl)
|
options, err := redis.ParseURL(redisUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal().Err(err).Msg("Cannot parse redis url")
|
log.Fatal().Err(err).Msg("Cannot parse redis url")
|
||||||
|
|||||||
Reference in New Issue
Block a user