From 9ac95672b9381b99e7f02e713fe555b5e221d072 Mon Sep 17 00:00:00 2001 From: Victor Lacasse-Beaudoin Date: Fri, 2 Jun 2023 16:21:14 -0400 Subject: [PATCH] Fix ApiClient.GetHealth Utiliser type handlers.GetHealthResponse Pointer vers route /v4/health --- data/apiclient.go | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/data/apiclient.go b/data/apiclient.go index 7143204..21ceecc 100644 --- a/data/apiclient.go +++ b/data/apiclient.go @@ -8,6 +8,7 @@ import ( "io/ioutil" "net/http" + "git.agecem.com/agecem/bottin/handlers" "git.agecem.com/agecem/bottin/models" "github.com/spf13/viper" ) @@ -79,33 +80,31 @@ func (a *ApiClient) Call(method, route string, requestBody io.Reader, useKey boo return response, nil } -// GetV4 allows checking for API v4 server health -func (a *ApiClient) GetV4() (string, error) { - var getV4Response struct { - Message string `json:"message"` - } +// GetHealth allows checking for API server health +func (a *ApiClient) GetHealth() (string, error) { + var getHealthResponse handlers.GetHealthResponse - response, err := a.Call(http.MethodGet, "/v4", nil, true) + response, err := a.Call(http.MethodGet, "/v4/health", nil, true) if err != nil { - return getV4Response.Message, err + return getHealthResponse.Message, err } defer response.Body.Close() body, err := ioutil.ReadAll(response.Body) if err != nil { - return getV4Response.Message, err + return getHealthResponse.Message, err } - if err := json.Unmarshal(body, &getV4Response); err != nil { - return getV4Response.Message, err + if err := json.Unmarshal(body, &getHealthResponse); err != nil { + return getHealthResponse.Message, err } - if getV4Response.Message == "" { - return getV4Response.Message, errors.New("Could not confirm that API server is up, no response message") + if getHealthResponse.Message == "" { + return getHealthResponse.Message, errors.New("Could not confirm that API server is up, no response message") } - return getV4Response.Message, nil + return getHealthResponse.Message, nil } func (a *ApiClient) GetMembre(membreID string) (models.Membre, error) {