-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.go
More file actions
104 lines (81 loc) · 2.26 KB
/
server.go
File metadata and controls
104 lines (81 loc) · 2.26 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// nolint:goconst
package mailpitclient
import (
"context"
"net/http"
)
// GetServerInfo retrieves server information and configuration.
func (c *client) GetServerInfo(ctx context.Context) (*ServerInfo, error) {
endpoint := "/info"
resp, err := c.makeRequest(ctx, http.MethodGet, endpoint, nil)
if err != nil {
return nil, err
}
var info ServerInfo
if err = c.parseResponse(resp, &info); err != nil {
return nil, err
}
return &info, nil
}
// HealthCheck performs a health check against the server.
// This is a simple check that verifies the server is responding.
func (c *client) HealthCheck(ctx context.Context) error {
endpoint := "/info"
resp, err := c.makeRequest(ctx, http.MethodGet, endpoint, nil)
if err != nil {
return err
}
defer resp.Body.Close()
// If we got here, the server is healthy
return nil
}
// GetStats retrieves server statistics including message counts and tags.
func (c *client) GetStats(ctx context.Context) (*Stats, error) {
endpoint := "/stats"
resp, err := c.makeRequest(ctx, http.MethodGet, endpoint, nil)
if err != nil {
return nil, err
}
var stats Stats
if err = c.parseResponse(resp, &stats); err != nil {
return nil, err
}
return &stats, nil
}
// GetTags retrieves all available message tags from the server.
func (c *client) GetTags(ctx context.Context) ([]string, error) {
endpoint := "/tags"
resp, err := c.makeRequest(ctx, http.MethodGet, endpoint, nil)
if err != nil {
return nil, err
}
var tags []string
if err = c.parseResponse(resp, &tags); err != nil {
return nil, err
}
return tags, nil
}
// Ping performs a simple ping to check if the server is reachable.
// This is a lightweight alternative to HealthCheck.
func (c *client) Ping(ctx context.Context) error {
endpoint := "/info"
resp, err := c.makeRequest(ctx, http.MethodHead, endpoint, nil)
if err != nil {
return err
}
defer resp.Body.Close()
return nil
}
// GetWebUIConfig retrieves the web UI configuration.
func (c *client) GetWebUIConfig(ctx context.Context) (*WebUIConfig, error) {
endpoint := "/webui"
resp, err := c.makeRequest(ctx, http.MethodGet, endpoint, nil)
if err != nil {
return nil, err
}
var config WebUIConfig
if err = c.parseResponse(resp, &config); err != nil {
return nil, err
}
return &config, nil
}