From e2a4e32daedee0ebac98b694c17b8d373c181363 Mon Sep 17 00:00:00 2001 From: lyx0 <66651385+lyx0@users.noreply.github.com> Date: Fri, 3 Mar 2023 21:16:32 +0000 Subject: [PATCH] add env flag for database connection --- cmd/bot/main.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/cmd/bot/main.go b/cmd/bot/main.go index 8a4b416..744d5e4 100644 --- a/cmd/bot/main.go +++ b/cmd/bot/main.go @@ -3,6 +3,7 @@ package main import ( "context" "database/sql" + "flag" "log" "os" "time" @@ -41,6 +42,13 @@ type Application struct { Scheduler *cron.Cron } +var envFlag string + +func init() { + flag.StringVar(&envFlag, "env", "dev", "database connection to use: (dev/prod)") + flag.Parse() +} + func main() { var cfg config @@ -62,11 +70,13 @@ func main() { cfg.commandPrefix = os.Getenv("TWITCH_COMMAND_PREFIX") tc := twitch.NewClient(cfg.twitchUsername, cfg.twitchOauth) - // Will be used someday Copesen - cfg.environment = "Development" - + switch envFlag { + case "dev": + cfg.db.dsn = os.Getenv("LOCAL_DSN") + case "prod": + cfg.db.dsn = os.Getenv("SUPABASE_DSN") + } // Database config variables - cfg.db.dsn = os.Getenv("DB_DSN") cfg.db.maxOpenConns = 25 cfg.db.maxIdleConns = 25 cfg.db.maxIdleTime = "15m"