Booking trace API
This commit is contained in:
21
tools/api.go
21
tools/api.go
@@ -20,6 +20,15 @@ const (
|
||||
DEAD
|
||||
)
|
||||
|
||||
func ToState(str string) State {
|
||||
for _, s := range []State{ALIVE, REDUCED_SERVICE, UNPROCESSABLE_ENTITY, DB_FALLOUT, TEAPOT, DEAD} {
|
||||
if s.String() == str {
|
||||
return s
|
||||
}
|
||||
}
|
||||
return DEAD
|
||||
}
|
||||
|
||||
func (s State) String() string {
|
||||
return [...]string{"alive", "reduced service", "unprocessable entity", "database fallout",
|
||||
"some things boils in here, i'm probably a teapot", "dead"}[s]
|
||||
@@ -47,6 +56,18 @@ func (a *API) GetState() (State, int, error) {
|
||||
return ALIVE, 200, nil
|
||||
}
|
||||
|
||||
func (a *API) CheckRemotePeer(url string) State {
|
||||
// Check if the database is up
|
||||
caller := NewHTTPCaller(map[string]map[METHOD]string{})
|
||||
var resp APIStatusResponse
|
||||
b, err := caller.CallGet(url, "/status")
|
||||
if err != nil {
|
||||
return DEAD
|
||||
}
|
||||
json.Unmarshal(b, &resp)
|
||||
return ToState(resp.Data.State)
|
||||
}
|
||||
|
||||
func (a *API) CheckRemoteAPIs(urls []string) (State, int, error) {
|
||||
// Check if the database is up
|
||||
caller := NewHTTPCaller(map[string]map[METHOD]string{})
|
||||
|
Reference in New Issue
Block a user