-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprovider_example.go
66 lines (54 loc) · 1.32 KB
/
provider_example.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
package hosttech
import (
"context"
"fmt"
"github.com/libdns/libdns"
"time"
)
func main() {
provider := Provider{
APIToken: "Your API token",
}
//Set your zone with the domain
zone := "example.com"
//List all records
allRecords, err := provider.GetRecords(context.Background(), zone)
if err != nil {
fmt.Println("Could not read record(s) because of", err.Error())
}
for _, record := range allRecords {
fmt.Println(record)
}
//Create a new record...
newlyCreatedRecords, err := provider.AppendRecords(context.Background(), zone, []libdns.Record{
{
ID: "",
Type: "A",
Name: "sub",
Value: "1.2.3.4",
TTL: 1800 * time.Second,
Priority: 0,
},
})
if err != nil {
fmt.Println("Could not create record(s) because of", err.Error())
}
//... and delete it afterwards again
for _, record := range newlyCreatedRecords {
deletedRecords, err := provider.DeleteRecords(context.Background(), zone, []libdns.Record{record})
if err != nil {
fmt.Println(err.Error())
}
for _, deletedRecord := range deletedRecords {
fmt.Println("Deleted record: ", deletedRecord)
}
}
//List all available zones
allZones, err := provider.ListZones(context.Background())
if err != nil {
fmt.Print(err.Error())
}
for _, zone := range allZones {
fmt.Println("Zone: ", zone.Name)
}
}