From 7823541f0eb77a0ab8cd1711355f9b953d35a1c2 Mon Sep 17 00:00:00 2001 From: Victor Lacasse-Beaudoin Date: Fri, 2 Jun 2023 03:17:43 -0400 Subject: [PATCH] =?UTF-8?q?Ajouter=20ping=20de=20database=20=C3=A0=20healt?= =?UTF-8?q?hcheck?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handlers/health.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/handlers/health.go b/handlers/health.go index d917738..49d45b0 100644 --- a/handlers/health.go +++ b/handlers/health.go @@ -1,8 +1,10 @@ package handlers import ( + "fmt" "net/http" + "git.agecem.com/agecem/bottin/v4/data" "github.com/labstack/echo/v4" ) @@ -11,7 +13,23 @@ type GetHealthResponse struct { } func GetHealth(c echo.Context) error { - response := GetHealthResponse{"Bottin API v4 is ready"} + response := GetHealthResponse{ + Message: "Bottin API v4 is ready", + } + + dataClient, err := data.NewDataClientFromViper() + if err != nil { + response.Message = fmt.Sprintf("Error during data.NewDataClientFromViper(): %s", err) + + return c.JSON(http.StatusInternalServerError, response) + } + defer dataClient.DB.Close() + + if err = dataClient.DB.Ping(); err != nil { + response.Message = fmt.Sprintf("Error during dataClient.DB.Ping(): %s", err) + + return c.JSON(http.StatusInternalServerError, response) + } return c.JSON(http.StatusOK, response) }