Implémenter Response dans GetHealthResponse

This commit is contained in:
Victor Lacasse-Beaudoin 2023-09-05 16:30:15 -04:00
parent a13bb131f4
commit 0f56348746
3 changed files with 16 additions and 13 deletions

View file

@ -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 {

View file

@ -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)
}

View file

@ -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
}