Merge pull request 'Defer DB.Close() sur chaque DataClient' (#22) from fix/defer-dataclient-close into main

Reviewed-on: #22
This commit is contained in:
Victor Lacasse-Beaudoin 2023-06-08 18:48:56 -05:00
commit ecb30b2d9b
2 changed files with 3 additions and 2 deletions

View file

@ -59,14 +59,13 @@ var apiCmd = &cobra.Command{
if err != nil {
log.Fatalf("Could not establish database connection.\n Error: %s\n", err)
}
defer client.DB.Close()
err = client.DB.Ping()
if err != nil {
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)))
},
}

View file

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