-
Notifications
You must be signed in to change notification settings - Fork 0
/
methods_health.go
39 lines (33 loc) · 1.25 KB
/
methods_health.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
package sourcify
import (
"net/http"
)
// MethodHealth represents the API endpoint for checking the server status in the Sourcify service.
// It includes the name, the HTTP method, the URI, and the parameters necessary for the request.
// Ping the server and see if it is alive and ready for requests.
// More information: https://docs.sourcify.dev/docs/api/health/
var MethodHealth = Method{
Name: "Show Server Status",
URI: "/health",
MoreInfo: "https://docs.sourcify.dev/docs/api/health/",
Method: "GET",
ParamType: MethodParamTypeUri,
RequiredParams: []string{},
Params: []MethodParam{},
}
// GetHealth checks the server status by calling the MethodHealth endpoint using the provided client.
// It returns a boolean indicating if the server is healthy and an error if any occurred during the request.
func GetHealth(client *Client) (bool, error) {
response, statusCode, err := client.CallMethod(MethodHealth)
if err != nil {
return false, err
}
// Close the io.ReadCloser interface
// This is important as CallMethod is NOT closing the response body!
// You'll have memory leaks if you don't do this!
defer response.Close()
if statusCode != http.StatusOK {
return false, nil
}
return true, nil
}