2023-06-02 02:35:15 -04:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2024-01-05 14:38:48 -05:00
|
|
|
"git.agecem.com/agecem/bottin/v6/data"
|
|
|
|
"git.agecem.com/agecem/bottin/v6/responses"
|
2023-06-02 02:35:15 -04:00
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
)
|
|
|
|
|
2023-09-18 22:55:40 -04:00
|
|
|
func (h *Handler) GetHealth(c echo.Context) error {
|
2023-09-05 16:30:15 -04:00
|
|
|
var response responses.GetHealthResponse
|
2023-06-02 03:17:43 -04:00
|
|
|
|
|
|
|
dataClient, err := data.NewDataClientFromViper()
|
|
|
|
if err != nil {
|
2023-09-05 16:30:15 -04:00
|
|
|
response.StatusCode = http.StatusInternalServerError
|
|
|
|
response.Message = "Error during data.NewDataClientFromViper()"
|
|
|
|
response.Error = err.Error()
|
2023-06-02 03:17:43 -04:00
|
|
|
|
2023-09-05 16:30:15 -04:00
|
|
|
return c.JSON(response.StatusCode, response)
|
2023-06-02 03:17:43 -04:00
|
|
|
}
|
|
|
|
defer dataClient.DB.Close()
|
|
|
|
|
|
|
|
if err = dataClient.DB.Ping(); err != nil {
|
2023-09-05 16:30:15 -04:00
|
|
|
response.StatusCode = http.StatusInternalServerError
|
|
|
|
response.Message = "Error during dataClient.DB.Ping()"
|
|
|
|
response.Error = err.Error()
|
2023-06-02 03:17:43 -04:00
|
|
|
|
2023-09-05 16:30:15 -04:00
|
|
|
return c.JSON(response.StatusCode, response)
|
2023-06-02 03:17:43 -04:00
|
|
|
}
|
2023-06-02 02:35:15 -04:00
|
|
|
|
2023-09-05 16:30:15 -04:00
|
|
|
response.StatusCode = http.StatusOK
|
2024-01-05 14:38:48 -05:00
|
|
|
response.Message = "Bottin API v6 is ready"
|
2023-09-05 16:30:15 -04:00
|
|
|
|
|
|
|
return c.JSON(response.StatusCode, response)
|
2023-06-02 02:35:15 -04:00
|
|
|
}
|