diff --git a/tools/api.go b/tools/api.go index 2c639a6..a83ee8f 100644 --- a/tools/api.go +++ b/tools/api.go @@ -1,6 +1,7 @@ package tools import ( + "encoding/json" "errors" "cloud.o-forge.io/core/oc-lib/dbs/mongo" @@ -50,10 +51,25 @@ func (a *API) CheckRemoteAPIs(urls []string) (State, int, error) { // Check if the database is up caller := NewHTTPCaller(map[string]map[METHOD]string{}) for _, url := range urls { - _, err := caller.CallGet(url, "/version/status") + var resp APIStatusResponse + b, err := caller.CallGet(url, "/version/status") if err != nil { return REDUCED_SERVICE, 200, err } + json.Unmarshal(b, &resp) + if resp.Data.Code != 0 { + return REDUCED_SERVICE, 200, errors.New(url + " -> " + resp.Error) + } } return ALIVE, 200, nil } + +type APIStatusResponse struct { + Data *APIStatus `json:"data"` + Error string `json:"error"` +} + +type APIStatus struct { + Code int `json:"code"` + State string `json:"state"` +}