package handlers import ( "net/http" "git.agecem.com/agecem/bottin-agenda/data" bottindata "git.agecem.com/agecem/bottin/v5/data" "github.com/labstack/echo/v4" "github.com/spf13/viper" ) func GetHealth(c echo.Context) error { 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" } } return c.JSON(http.StatusOK, map[string]string{ "message": "Bottin-agenda API v2 is ready", "bottin": bottinStatus, "database": databaseStatus, }) }