2023-06-02 02:35:15 -04:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
2023-06-02 03:17:43 -04:00
|
|
|
"fmt"
|
2023-06-02 02:35:15 -04:00
|
|
|
"net/http"
|
|
|
|
|
2023-06-02 16:08:08 -04:00
|
|
|
"git.agecem.com/agecem/bottin/data"
|
2023-06-02 02:35:15 -04:00
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
)
|
|
|
|
|
|
|
|
type GetHealthResponse struct {
|
|
|
|
Message string `json:"message"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetHealth(c echo.Context) error {
|
2023-06-02 03:17:43 -04:00
|
|
|
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)
|
|
|
|
}
|
2023-06-02 02:35:15 -04:00
|
|
|
|
|
|
|
return c.JSON(http.StatusOK, response)
|
|
|
|
}
|