-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprovider.go
58 lines (48 loc) · 1.38 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
package tencentcloud
import (
"context"
"errors"
"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 {
if err := p.findRecord(ctx, zone, record); err != nil {
if errors.Is(err, ErrRecordNotFound) {
if err := p.createRecord(ctx, zone, record); err != nil {
return nil, err
}
continue
}
}
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 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)
)