-
Notifications
You must be signed in to change notification settings - Fork 23
/
http_health_checks.go
55 lines (43 loc) · 1.15 KB
/
http_health_checks.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
47
48
49
50
51
52
53
54
55
package compute
import (
"fmt"
"strings"
"github.com/genevieve/leftovers/common"
gcpcompute "google.golang.org/api/compute/v1"
)
type httpHealthChecksClient interface {
ListHttpHealthChecks() ([]*gcpcompute.HttpHealthCheck, error)
DeleteHttpHealthCheck(httpHealthCheck string) error
}
type HttpHealthChecks struct {
client httpHealthChecksClient
logger logger
}
func NewHttpHealthChecks(client httpHealthChecksClient, logger logger) HttpHealthChecks {
return HttpHealthChecks{
client: client,
logger: logger,
}
}
func (h HttpHealthChecks) List(filter string) ([]common.Deletable, error) {
checks, err := h.client.ListHttpHealthChecks()
if err != nil {
return nil, fmt.Errorf("List Http Health Checks: %s", err)
}
var resources []common.Deletable
for _, check := range checks {
resource := NewHttpHealthCheck(h.client, check.Name)
if !strings.Contains(check.Name, filter) {
continue
}
proceed := h.logger.PromptWithDetails(resource.Type(), resource.Name())
if !proceed {
continue
}
resources = append(resources, resource)
}
return resources, nil
}
func (h HttpHealthChecks) Type() string {
return "http-health-check"
}