[BREAKING] Déplacer route /v4 vers /v4/health #12
1 changed files with 19 additions and 1 deletions
|
@ -1,8 +1,10 @@
|
||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"git.agecem.com/agecem/bottin/v4/data"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -11,7 +13,23 @@ type GetHealthResponse struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetHealth(c echo.Context) error {
|
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)
|
return c.JSON(http.StatusOK, response)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue