feat: defer function, add info to string var dsn
This commit is contained in:
@@ -54,7 +54,7 @@ func main() {
|
|||||||
flag.StringVar(&cfg.env, "env", "development", "Environment (development|staging|production)")
|
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
|
// 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.
|
// 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()
|
flag.Parse()
|
||||||
|
|
||||||
@@ -68,8 +68,11 @@ func main() {
|
|||||||
|
|
||||||
// Defer a call to db.Close() so that the connection pool is closed before the
|
// Defer a call to db.Close() so that the connection pool is closed before the
|
||||||
// main() function exits.
|
// 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
|
// Also log a message to say that the connection pool has been successfully
|
||||||
// established.
|
// established.
|
||||||
logger.Printf("database connection pool established")
|
logger.Printf("database connection pool established")
|
||||||
|
|||||||
Reference in New Issue
Block a user