2023-06-02 02:35:15 -04:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2023-06-02 17:46:57 -04:00
|
|
|
"git.agecem.com/agecem/bottin/v5/data"
|
|
|
|
"git.agecem.com/agecem/bottin/v5/responses"
|
2023-06-02 02:35:15 -04:00
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
)
|
|
|
|
|
|
|
|
func 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
|
|
|
|
response.Message = "Bottin API v5 is ready"
|
|
|
|
|
|
|
|
return c.JSON(response.StatusCode, response)
|
2023-06-02 02:35:15 -04:00
|
|
|
}
|