simplify call to peer

This commit is contained in:
mr
2024-08-23 15:43:12 +02:00
parent 5b3779e4cb
commit 1986143dd0
2 changed files with 11 additions and 2 deletions

View File

@@ -84,6 +84,9 @@ func (a *API) CheckRemoteAPIs(urls map[string]string) (State, map[string]string,
// Check if the database is up
new := map[string]string{}
caller := NewHTTPCaller(map[string]map[METHOD]string{})
code := 0
u := ""
e := ""
for appName, url := range urls {
var resp APIStatusResponse
b, err := caller.CallGet(url, "/version/status")
@@ -95,10 +98,15 @@ func (a *API) CheckRemoteAPIs(urls map[string]string) (State, map[string]string,
return DEAD, new, errors.New(url + " -> is DEAD")
}
new[appName] = resp.Data.State
if resp.Data.Code != 0 {
return REDUCED_SERVICE, new, errors.New(url + " -> " + resp.Error)
if resp.Data.Code > code {
code = resp.Data.Code
u = url
e += resp.Error
}
}
if code > 0 {
return REDUCED_SERVICE, new, errors.New(u + " -> " + e)
}
return ALIVE, new, nil
}