diff options
author | Matthew Lemon <y@yulqen.org> | 2024-04-10 15:12:12 +0100 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-04-10 15:12:12 +0100 |
commit | 50d6737b0c81869d77486fded1476f55917b940b (patch) | |
tree | 875151701dd1cf758130f28fb186cc4af86fcf75 /cmd/dbasik-api/main.go | |
parent | b408be58debc72322fa1680a8f7293b9ba3b571f (diff) |
Adds .env file with database dsn in it
Diffstat (limited to 'cmd/dbasik-api/main.go')
-rw-r--r-- | cmd/dbasik-api/main.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/cmd/dbasik-api/main.go b/cmd/dbasik-api/main.go index e1f93d5..e296551 100644 --- a/cmd/dbasik-api/main.go +++ b/cmd/dbasik-api/main.go @@ -25,11 +25,13 @@ import ( "database/sql" "flag" "fmt" + "log" "log/slog" "net/http" "os" "time" + "github.com/joho/godotenv" _ "github.com/lib/pq" ) @@ -56,10 +58,15 @@ func main() { // Instance of config var cfg config + err := godotenv.Load() + if err != nil { + log.Fatal("Cannot load .env file - is it present?") + } + // Read the flags into the config struct. Defaults are provided if none given. flag.IntVar(&cfg.port, "port", 5000, "API server port") flag.StringVar(&cfg.env, "env", "development", "Environment (development|staging|production)") - flag.StringVar(&cfg.db.dsn, "db-dsn", "postgres://dbasik:dbasik@db/dbasik?sslmode=disable", "PostgreSQL DSN") + flag.StringVar(&cfg.db.dsn, "db-dsn", os.Getenv("DBASIK_DB_DSN"), "PostgreSQL DSN") flag.Parse() // Initialize a new structured logger which writes to stdout |