bottin/handlers/health.go

37 lines
925 B
Go
Raw Normal View History

package handlers
import (
"net/http"
"git.agecem.com/agecem/bottin/v6/data"
"git.agecem.com/agecem/bottin/v6/responses"
"github.com/labstack/echo/v4"
)
func (h *Handler) GetHealth(c echo.Context) error {
var response responses.GetHealthResponse
dataClient, err := data.NewDataClientFromViper()
if err != nil {
response.StatusCode = http.StatusInternalServerError
response.Message = "Error during data.NewDataClientFromViper()"
response.Error = err.Error()
return c.JSON(response.StatusCode, response)
}
defer dataClient.DB.Close()
if err = dataClient.DB.Ping(); err != nil {
response.StatusCode = http.StatusInternalServerError
response.Message = "Error during dataClient.DB.Ping()"
response.Error = err.Error()
return c.JSON(response.StatusCode, response)
}
response.StatusCode = http.StatusOK
response.Message = "Bottin API v6 is ready"
return c.JSON(response.StatusCode, response)
}