add env flag for database connection

This commit is contained in:
lyx0 2023-03-03 21:16:32 +00:00
parent 0ff77d63b3
commit e2a4e32dae

View file

@ -3,6 +3,7 @@ package main
import ( import (
"context" "context"
"database/sql" "database/sql"
"flag"
"log" "log"
"os" "os"
"time" "time"
@ -41,6 +42,13 @@ type Application struct {
Scheduler *cron.Cron Scheduler *cron.Cron
} }
var envFlag string
func init() {
flag.StringVar(&envFlag, "env", "dev", "database connection to use: (dev/prod)")
flag.Parse()
}
func main() { func main() {
var cfg config var cfg config
@ -62,11 +70,13 @@ func main() {
cfg.commandPrefix = os.Getenv("TWITCH_COMMAND_PREFIX") cfg.commandPrefix = os.Getenv("TWITCH_COMMAND_PREFIX")
tc := twitch.NewClient(cfg.twitchUsername, cfg.twitchOauth) tc := twitch.NewClient(cfg.twitchUsername, cfg.twitchOauth)
// Will be used someday Copesen switch envFlag {
cfg.environment = "Development" case "dev":
cfg.db.dsn = os.Getenv("LOCAL_DSN")
case "prod":
cfg.db.dsn = os.Getenv("SUPABASE_DSN")
}
// Database config variables // Database config variables
cfg.db.dsn = os.Getenv("DB_DSN")
cfg.db.maxOpenConns = 25 cfg.db.maxOpenConns = 25
cfg.db.maxIdleConns = 25 cfg.db.maxIdleConns = 25
cfg.db.maxIdleTime = "15m" cfg.db.maxIdleTime = "15m"