-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhealth.go
More file actions
62 lines (50 loc) · 1.41 KB
/
health.go
File metadata and controls
62 lines (50 loc) · 1.41 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package gotenberg
import (
"context"
"encoding/json"
"io"
"github.com/nativebpm/connectors/httpstream"
)
// HealthResponse represents the response from the health check endpoint.
type HealthResponse struct {
Status string `json:"status"`
Details map[string]any `json:"details"`
}
// GetHealth performs a health check on the Gotenberg service.
// It returns the overall status and details about each module (e.g., Chromium, LibreOffice).
func (c *Client) GetHealth(ctx context.Context) (*HealthResponse, error) {
resp, err := c.HttpStream.Request(ctx, httpstream.GET, "/health").Send()
if err != nil {
return nil, err
}
defer resp.Body.Close()
var healthResp HealthResponse
if err := json.NewDecoder(resp.Body).Decode(&healthResp); err != nil {
return nil, err
}
return &healthResp, nil
}
func (c *Client) GetVersion(ctx context.Context) (string, error) {
resp, err := c.HttpStream.Request(ctx, httpstream.GET, "/version").Send()
if err != nil {
return "", err
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}
return string(body), nil
}
func (c *Client) GetMetrics(ctx context.Context) (string, error) {
resp, err := c.HttpStream.Request(ctx, httpstream.GET, "/prometheus/metrics").Send()
if err != nil {
return "", err
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}
return string(body), nil
}