bottin/handlers/health.go
Victor Lacasse-Beaudoin 764093f99d Bump routes v4 -> v5
Remplacer références GetV4 -> GetHealth

Ajouter package responses

Remplacer handlers.GetHealthResponse -> responses.GetHealth
2023-06-02 16:33:13 -04:00

32 lines
750 B
Go

package handlers
import (
"fmt"
"net/http"
"git.agecem.com/agecem/bottin/data"
"git.agecem.com/agecem/bottin/responses"
"github.com/labstack/echo/v4"
)
func GetHealth(c echo.Context) error {
response := responses.GetHealth{
Message: "Bottin API v5 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)
}