From 9a6ab5c29c43e3cbd846e92038c83a4290eeaa17 Mon Sep 17 00:00:00 2001 From: mr Date: Wed, 21 Aug 2024 15:32:10 +0200 Subject: [PATCH] Booking trace API --- tools/api.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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"` +}