diff --git a/data/apiclient.go b/data/apiclient.go index 2f1f1ae..3319d72 100644 --- a/data/apiclient.go +++ b/data/apiclient.go @@ -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 { diff --git a/handlers/health.go b/handlers/health.go index f8baece..d4fe868 100644 --- a/handlers/health.go +++ b/handlers/health.go @@ -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) } diff --git a/responses/health.go b/responses/health.go index 6d5e663..854279d 100644 --- a/responses/health.go +++ b/responses/health.go @@ -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 }