Defer DB.Close() sur chaque DataClient #22

Merged
vlbeaudoin merged 1 commit from fix/defer-dataclient-close into main 2023-06-08 19:48:57 -04:00
2 changed files with 3 additions and 2 deletions

View file

@ -59,14 +59,13 @@ var apiCmd = &cobra.Command{
if err != nil { if err != nil {
log.Fatalf("Could not establish database connection.\n Error: %s\n", err) log.Fatalf("Could not establish database connection.\n Error: %s\n", err)
} }
defer client.DB.Close()
err = client.DB.Ping() err = client.DB.Ping()
if err != nil { if err != nil {
log.Fatalf("Database was supposed to be ready but Ping() failed.\n Error: %s\n", err) log.Fatalf("Database was supposed to be ready but Ping() failed.\n Error: %s\n", err)
} }
client.DB.Close()
e.Logger.Fatal(e.Start(fmt.Sprintf(":%d", apiPort))) e.Logger.Fatal(e.Start(fmt.Sprintf(":%d", apiPort)))
}, },
} }

View file

@ -16,6 +16,7 @@ func PostMembres(c echo.Context) error {
"error": err.Error(), "error": err.Error(),
}) })
} }
defer client.DB.Close()
var membres []models.Membre var membres []models.Membre
@ -56,6 +57,7 @@ func PostProgrammes(c echo.Context) error {
"error": err.Error(), "error": err.Error(),
}) })
} }
defer client.DB.Close()
var programmes []models.Programme var programmes []models.Programme