-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathprovider.go
68 lines (58 loc) · 1.59 KB
/
provider.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
56
57
58
59
60
61
62
63
64
65
66
67
68
package tencentcloud
import (
"context"
"errors"
"strconv"
"github.com/libdns/libdns"
)
func (p *Provider) GetRecords(ctx context.Context, zone string) ([]libdns.Record, error) {
return p.listRecords(ctx, zone)
}
func (p *Provider) AppendRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error) {
for _, record := range records {
if err := p.createRecord(ctx, zone, record); err != nil {
return nil, err
}
}
return records, nil
}
func (p *Provider) SetRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error) {
for _, record := range records {
id, err := p.findRecord(ctx, zone, record)
if err != nil {
if errors.Is(err, ErrRecordNotFound) {
if err = p.createRecord(ctx, zone, record); err != nil {
return nil, err
}
continue
}
}
record.ID = strconv.FormatUint(id, 10)
if err = p.modifyRecord(ctx, zone, record); err != nil {
return nil, err
}
}
return records, nil
}
func (p *Provider) DeleteRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error) {
for _, record := range records {
if record.ID == "" {
id, err := p.findRecord(ctx, zone, record)
if err != nil {
return nil, err
}
record.ID = strconv.FormatUint(id, 10)
}
if err := p.deleteRecord(ctx, zone, record); err != nil {
return nil, err
}
}
return records, nil
}
// Interface guards
var (
_ libdns.RecordGetter = (*Provider)(nil)
_ libdns.RecordAppender = (*Provider)(nil)
_ libdns.RecordSetter = (*Provider)(nil)
_ libdns.RecordDeleter = (*Provider)(nil)
)