From 3870ef42dd24d1cb27d85ae5cb7577405d4a14ab Mon Sep 17 00:00:00 2001 From: Victor Lacasse-Beaudoin Date: Thu, 8 Jun 2023 19:47:25 -0400 Subject: [PATCH] Defer DB.Close() sur chaque DataClient --- cmd/api.go | 3 +-- handlers/insert.go | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/api.go b/cmd/api.go index e44ab61..4d6a30e 100644 --- a/cmd/api.go +++ b/cmd/api.go @@ -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))) }, } diff --git a/handlers/insert.go b/handlers/insert.go index b928942..0fc6238 100644 --- a/handlers/insert.go +++ b/handlers/insert.go @@ -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 -- 2.45.2