Merge branch 'rework/get-health-response' into main
This commit is contained in:
commit
4a4e35b76c
3 changed files with 16 additions and 13 deletions
|
@ -77,7 +77,7 @@ func (a *ApiClient) Call(method, route string, requestBody io.Reader, useKey boo
|
|||
|
||||
// GetHealth allows checking for API server health
|
||||
func (a *ApiClient) GetHealth() (string, error) {
|
||||
var getHealthResponse responses.GetHealth
|
||||
var getHealthResponse responses.GetHealthResponse
|
||||
|
||||
response, err := a.Call(http.MethodGet, "/v5/health", nil, true)
|
||||
if err != nil {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"git.agecem.com/agecem/bottin/v5/data"
|
||||
|
@ -10,23 +9,28 @@ import (
|
|||
)
|
||||
|
||||
func GetHealth(c echo.Context) error {
|
||||
response := responses.GetHealth{
|
||||
Message: "Bottin API v5 is ready",
|
||||
}
|
||||
var response responses.GetHealthResponse
|
||||
|
||||
dataClient, err := data.NewDataClientFromViper()
|
||||
if err != nil {
|
||||
response.Message = fmt.Sprintf("Error during data.NewDataClientFromViper(): %s", err)
|
||||
response.StatusCode = http.StatusInternalServerError
|
||||
response.Message = "Error during data.NewDataClientFromViper()"
|
||||
response.Error = err.Error()
|
||||
|
||||
return c.JSON(http.StatusInternalServerError, response)
|
||||
return c.JSON(response.StatusCode, response)
|
||||
}
|
||||
defer dataClient.DB.Close()
|
||||
|
||||
if err = dataClient.DB.Ping(); err != nil {
|
||||
response.Message = fmt.Sprintf("Error during dataClient.DB.Ping(): %s", err)
|
||||
response.StatusCode = http.StatusInternalServerError
|
||||
response.Message = "Error during dataClient.DB.Ping()"
|
||||
response.Error = err.Error()
|
||||
|
||||
return c.JSON(http.StatusInternalServerError, response)
|
||||
return c.JSON(response.StatusCode, response)
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, response)
|
||||
response.StatusCode = http.StatusOK
|
||||
response.Message = "Bottin API v5 is ready"
|
||||
|
||||
return c.JSON(response.StatusCode, response)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package responses
|
||||
|
||||
// GetHealth is the response type for handlers.GetHealth
|
||||
type GetHealth struct {
|
||||
Message string `json:"message"`
|
||||
type GetHealthResponse struct {
|
||||
Response
|
||||
}
|
||||
|
|
Reference in a new issue