-
Notifications
You must be signed in to change notification settings - Fork 15
/
status.go
40 lines (34 loc) · 1.06 KB
/
status.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright 2020 by Red Hat, Inc. All rights reserved.
// Use of this source is goverend by the Apache License
// that can be found in the LICENSE file.
package weldr
import (
"encoding/json"
"io"
)
// ServerStatus returns the status of the API server
func (c Client) ServerStatus() (StatusV0, *APIResponse, error) {
resp, err := c.RequestRawURL("GET", "/api/status", "", map[string]string{})
if err != nil {
return StatusV0{}, nil, err
}
// Convert the API's JSON error response to an error type and return it
// lorax-composer (wrongly) returns 404 for some of its json responses
if resp.StatusCode == 400 || resp.StatusCode == 404 {
apiResponse, err := c.apiError(resp)
return StatusV0{}, apiResponse, err
}
defer resp.Body.Close()
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return StatusV0{}, nil, err
}
// Pass the body to the callback function
c.rawFunc("GET", "/api/status", 200, bodyBytes)
var status StatusV0
err = json.Unmarshal(bodyBytes, &status)
if err != nil {
return StatusV0{}, nil, err
}
return status, nil, nil
}