From 0ac448a9ba78cdf60b6b4087ef3195971a750462 Mon Sep 17 00:00:00 2001 From: lyx0 <66651385+lyx0@users.noreply.github.com> Date: Thu, 7 Dec 2023 17:49:32 +0100 Subject: [PATCH] move environment to run in into .env file --- Dockerfile | 2 +- cmd/nourybot/main.go | 13 ++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index e080a68..cb4461f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,4 +20,4 @@ RUN go get -d -v ./... RUN go build ./cmd/nourybot # Run the executable -CMD [ "./nourybot", "env='prod'" ] +CMD [ "./nourybot" ] diff --git a/cmd/nourybot/main.go b/cmd/nourybot/main.go index 45ac3a3..8a7d358 100644 --- a/cmd/nourybot/main.go +++ b/cmd/nourybot/main.go @@ -3,7 +3,6 @@ package main import ( "context" "database/sql" - "flag" "fmt" "os" "time" @@ -26,6 +25,7 @@ type config struct { twitchClientSecret string twitchID string commandPrefix string + env string db struct { dsn string maxOpenConns int @@ -44,12 +44,6 @@ type application struct { // Rdb *redis.Client } -var envFlag string - -func init() { - flag.StringVar(&envFlag, "env", "prod", "database connection to use: (dev/prod)") - flag.Parse() -} func main() { var cfg config // Initialize a new sugared logger that we'll pass on @@ -76,9 +70,10 @@ func main() { cfg.twitchClientSecret = os.Getenv("TWITCH_CLIENT_SECRET") cfg.commandPrefix = os.Getenv("TWITCH_COMMAND_PREFIX") cfg.twitchID = os.Getenv("TWITCH_ID") + cfg.env = os.Getenv("ENV") tc := twitch.NewClient(cfg.twitchUsername, cfg.twitchOauth) - switch envFlag { + switch cfg.env { case "dev": cfg.db.dsn = os.Getenv("DEV_DSN") case "prod": @@ -188,7 +183,7 @@ func main() { // Successfully connected to Twitch app.Log.Infow("Successfully connected to Twitch Servers", "Bot username", cfg.twitchUsername, - "Environment", envFlag, + "Environment", cfg.env, "Database Open Conns", cfg.db.maxOpenConns, "Database Idle Conns", cfg.db.maxIdleConns, "Database Idle Time", cfg.db.maxIdleTime,