2023-05-29 17:58:23 -04:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2023-06-03 20:16:41 -04:00
|
|
|
"git.agecem.com/agecem/bottin-agenda/data"
|
2023-06-03 19:48:37 -04:00
|
|
|
bottindata "git.agecem.com/agecem/bottin/v5/data"
|
2023-05-29 17:58:23 -04:00
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
2023-06-03 19:48:37 -04:00
|
|
|
func GetHealth(c echo.Context) error {
|
2023-05-29 17:58:23 -04:00
|
|
|
bottinApiKey := viper.GetString("bottin.api.key")
|
|
|
|
bottinApiHost := viper.GetString("bottin.api.host")
|
|
|
|
bottinApiProtocol := viper.GetString("bottin.api.protocol")
|
|
|
|
bottinApiPort := viper.GetInt("bottin.api.port")
|
|
|
|
|
2023-06-03 19:48:37 -04:00
|
|
|
bottinConnection := bottindata.NewApiClient(
|
2023-05-29 17:58:23 -04:00
|
|
|
bottinApiKey,
|
|
|
|
bottinApiHost,
|
|
|
|
bottinApiProtocol,
|
|
|
|
bottinApiPort,
|
|
|
|
)
|
|
|
|
|
|
|
|
var bottinStatus string
|
|
|
|
|
2023-06-03 19:48:37 -04:00
|
|
|
healthResponse, err := bottinConnection.GetHealth()
|
2023-05-29 17:58:23 -04:00
|
|
|
if err != nil {
|
|
|
|
bottinStatus = err.Error()
|
|
|
|
} else {
|
2023-06-03 19:48:37 -04:00
|
|
|
bottinStatus = healthResponse
|
2023-05-29 17:58:23 -04:00
|
|
|
}
|
|
|
|
|
2023-06-03 20:16:41 -04:00
|
|
|
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"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-29 17:58:23 -04:00
|
|
|
return c.JSON(http.StatusOK, map[string]string{
|
2023-06-03 20:16:41 -04:00
|
|
|
"message": "Bottin-agenda API v2 is ready",
|
|
|
|
"bottin": bottinStatus,
|
|
|
|
"database": databaseStatus,
|
2023-05-29 17:58:23 -04:00
|
|
|
})
|
|
|
|
}
|