-
Notifications
You must be signed in to change notification settings - Fork 1
/
health.go
46 lines (38 loc) · 839 Bytes
/
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
40
41
42
43
44
45
46
package consulapi
import (
"context"
"encoding/json"
"fmt"
"net/http"
)
type HealthService struct {
ID string
Service string
Address string
Port int
}
type HealthServiceEntry struct {
Service HealthService
}
type Health struct {
client *client
}
func (h *Health) Connect(ctx context.Context, service string, passing bool) ([]HealthServiceEntry, error) {
path := fmt.Sprintf("/v1/health/connect/%v?passing=%v", service, passing)
resp, err := h.client.Request(ctx, http.MethodGet, path, nil)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var entries []HealthServiceEntry
if err := json.NewDecoder(resp.Body).Decode(&entries); err != nil {
return nil, err
}
return entries, nil
}
func NewHealth(opts ...Option) *Health {
client := newClient(opts...)
return &Health{
client: client,
}
}