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-08 21:06:04 -04:00
|
|
|
"git.agecem.com/agecem/bottin-agenda/responses"
|
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-06-08 21:06:04 -04:00
|
|
|
var response responses.GetHealthResponse
|
|
|
|
var statusCode int = http.StatusNotImplemented
|
|
|
|
|
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-12-28 13:30:32 -05:00
|
|
|
bottinClient := http.DefaultClient
|
|
|
|
defer bottinClient.CloseIdleConnections()
|
|
|
|
|
2023-06-03 19:48:37 -04:00
|
|
|
bottinConnection := bottindata.NewApiClient(
|
2023-12-28 13:30:32 -05:00
|
|
|
bottinClient,
|
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-06-08 21:06:04 -04:00
|
|
|
statusCode = http.StatusOK
|
|
|
|
response.Message = "Bottin-agenda API v3 is ready"
|
|
|
|
response.Data.Bottin = bottinStatus
|
|
|
|
response.Data.Database = databaseStatus
|
|
|
|
|
|
|
|
return c.JSON(statusCode, response)
|
2023-05-29 17:58:23 -04:00
|
|
|
}
|