diff --git a/projects/greenlight/cmd/api/main.go b/projects/greenlight/cmd/api/main.go index 98423e4..088da3d 100644 --- a/projects/greenlight/cmd/api/main.go +++ b/projects/greenlight/cmd/api/main.go @@ -54,7 +54,7 @@ func main() { flag.StringVar(&cfg.env, "env", "development", "Environment (development|staging|production)") // Read the DSN value from the db-dsn command-line flag into the config struct. We // default to using our development DSN if no flag is provided. - flag.StringVar(&cfg.db.dsn, "db-dsn", dsn, "PostgreSQL DSN") + flag.StringVar(&cfg.db.dsn, "db-dsn", dsn, "PostgreSQL DSN (From DATABASE_DSN in .env)") flag.Parse() @@ -68,8 +68,11 @@ func main() { // Defer a call to db.Close() so that the connection pool is closed before the // main() function exits. - defer db.Close() - + defer func() { + if closeErr := db.Close(); closeErr != nil && err == nil { + err = closeErr + } + }() // Also log a message to say that the connection pool has been successfully // established. logger.Printf("database connection pool established")