-
Notifications
You must be signed in to change notification settings - Fork 22
/
client.go
54 lines (43 loc) · 1.28 KB
/
client.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
package dns
import (
gcpdns "google.golang.org/api/dns/v1"
"google.golang.org/api/googleapi"
)
type client struct {
project string
managedZones *gcpdns.ManagedZonesService
changes *gcpdns.ChangesService
recordSets *gcpdns.ResourceRecordSetsService
}
func NewClient(project string, service *gcpdns.Service) client {
return client{
project: project,
managedZones: service.ManagedZones,
changes: service.Changes,
recordSets: service.ResourceRecordSets,
}
}
func (c client) ListManagedZones() (*gcpdns.ManagedZonesListResponse, error) {
return c.managedZones.List(c.project).Do()
}
func (c client) DeleteManagedZone(managedZone string) error {
err := c.managedZones.Delete(c.project, managedZone).Do()
return handleNotFoundError(err)
}
func (c client) ListRecordSets(managedZone string) (*gcpdns.ResourceRecordSetsListResponse, error) {
return c.recordSets.List(c.project, managedZone).Do()
}
func (c client) DeleteRecordSets(managedZone string, change *gcpdns.Change) error {
_, err := c.changes.Create(c.project, managedZone, change).Do()
return handleNotFoundError(err)
}
func handleNotFoundError(err error) error {
if err != nil {
gerr, ok := err.(*googleapi.Error)
if ok && gerr != nil && gerr.Code == 404 {
return nil
}
return err
}
return nil
}