package handlers import ( "net/http" "git.agecem.com/agecem/bottin-agenda/data" "git.agecem.com/agecem/bottin-agenda/responses" bottindata "git.agecem.com/agecem/bottin/v5/data" "github.com/labstack/echo/v4" "github.com/spf13/viper" ) func GetHealth(c echo.Context) error { var response responses.GetHealthResponse var statusCode int = http.StatusNotImplemented bottinApiKey := viper.GetString("bottin.api.key") bottinApiHost := viper.GetString("bottin.api.host") bottinApiProtocol := viper.GetString("bottin.api.protocol") bottinApiPort := viper.GetInt("bottin.api.port") bottinConnection := bottindata.NewApiClient( bottinApiKey, bottinApiHost, bottinApiProtocol, bottinApiPort, ) var bottinStatus string healthResponse, err := bottinConnection.GetHealth() if err != nil { bottinStatus = err.Error() } else { bottinStatus = healthResponse } var databaseStatus string // Check database is ready dataClient, err := data.NewDataClientFromViper() if err != nil { databaseStatus = err.Error() } else { defer dataClient.DB.Close() if err := dataClient.DB.Ping(); err != nil { databaseStatus = err.Error() } else { databaseStatus = "Bottin-agenda database is ready" } } statusCode = http.StatusOK response.Message = "Bottin-agenda API v3 is ready" response.Data.Bottin = bottinStatus response.Data.Database = databaseStatus return c.JSON(statusCode, response) }