Fix ApiClient.GetHealth
Utiliser type handlers.GetHealthResponse Pointer vers route /v4/health
This commit is contained in:
parent
883edccf87
commit
9ac95672b9
1 changed files with 12 additions and 13 deletions
|
@ -8,6 +8,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"git.agecem.com/agecem/bottin/handlers"
|
||||||
"git.agecem.com/agecem/bottin/models"
|
"git.agecem.com/agecem/bottin/models"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
@ -79,33 +80,31 @@ func (a *ApiClient) Call(method, route string, requestBody io.Reader, useKey boo
|
||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetV4 allows checking for API v4 server health
|
// GetHealth allows checking for API server health
|
||||||
func (a *ApiClient) GetV4() (string, error) {
|
func (a *ApiClient) GetHealth() (string, error) {
|
||||||
var getV4Response struct {
|
var getHealthResponse handlers.GetHealthResponse
|
||||||
Message string `json:"message"`
|
|
||||||
}
|
|
||||||
|
|
||||||
response, err := a.Call(http.MethodGet, "/v4", nil, true)
|
response, err := a.Call(http.MethodGet, "/v4/health", nil, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return getV4Response.Message, err
|
return getHealthResponse.Message, err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(response.Body)
|
body, err := ioutil.ReadAll(response.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return getV4Response.Message, err
|
return getHealthResponse.Message, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := json.Unmarshal(body, &getV4Response); err != nil {
|
if err := json.Unmarshal(body, &getHealthResponse); err != nil {
|
||||||
return getV4Response.Message, err
|
return getHealthResponse.Message, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if getV4Response.Message == "" {
|
if getHealthResponse.Message == "" {
|
||||||
return getV4Response.Message, errors.New("Could not confirm that API server is up, no response 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) {
|
func (a *ApiClient) GetMembre(membreID string) (models.Membre, error) {
|
||||||
|
|
Loading…
Reference in a new issue