Merge branch 'rework/get-health-response' into main

This commit is contained in:
Victor Lacasse-Beaudoin 2023-09-05 16:31:36 -04:00
commit 4a4e35b76c
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 // GetHealth allows checking for API server health
func (a *ApiClient) GetHealth() (string, error) { func (a *ApiClient) GetHealth() (string, error) {
var getHealthResponse responses.GetHealth var getHealthResponse responses.GetHealthResponse
response, err := a.Call(http.MethodGet, "/v5/health", nil, true) response, err := a.Call(http.MethodGet, "/v5/health", nil, true)
if err != nil { if err != nil {

View file

@ -1,7 +1,6 @@
package handlers package handlers
import ( import (
"fmt"
"net/http" "net/http"
"git.agecem.com/agecem/bottin/v5/data" "git.agecem.com/agecem/bottin/v5/data"
@ -10,23 +9,28 @@ import (
) )
func GetHealth(c echo.Context) error { func GetHealth(c echo.Context) error {
response := responses.GetHealth{ var response responses.GetHealthResponse
Message: "Bottin API v5 is ready",
}
dataClient, err := data.NewDataClientFromViper() dataClient, err := data.NewDataClientFromViper()
if err != nil { 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() defer dataClient.DB.Close()
if err = dataClient.DB.Ping(); err != nil { 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 package responses
// GetHealth is the response type for handlers.GetHealth type GetHealthResponse struct {
type GetHealth struct { Response
Message string `json:"message"`
} }