forked from cloudflare/cloudflare-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dns_example_test.go
100 lines (82 loc) · 1.98 KB
/
dns_example_test.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package cloudflare_test
import (
"fmt"
"log"
cloudflare "github.com/cloudflare/cloudflare-go"
)
func ExampleAPI_DNSRecords_all() {
api, err := cloudflare.New("deadbeef", "[email protected]")
if err != nil {
log.Fatal(err)
}
zoneID, err := api.ZoneIDByName("example.com")
if err != nil {
log.Fatal(err)
}
// Fetch all records for a zone
recs, err := api.DNSRecords(zoneID, cloudflare.DNSRecord{})
if err != nil {
log.Fatal(err)
}
for _, r := range recs {
fmt.Printf("%s: %s\n", r.Name, r.Content)
}
}
func ExampleAPI_DNSRecords_filterByContent() {
api, err := cloudflare.New("deadbeef", "[email protected]")
if err != nil {
log.Fatal(err)
}
zoneID, err := api.ZoneIDByName("example.com")
if err != nil {
log.Fatal(err)
}
// Fetch only records whose content is 127.0.0.1
localhost := cloudflare.DNSRecord{Content: "127.0.0.1"}
recs, err := api.DNSRecords(zoneID, localhost)
if err != nil {
log.Fatal(err)
}
for _, r := range recs {
fmt.Printf("%s: %s\n", r.Name, r.Content)
}
}
func ExampleAPI_DNSRecords_filterByName() {
api, err := cloudflare.New("deadbeef", "[email protected]")
if err != nil {
log.Fatal(err)
}
zoneID, err := api.ZoneIDByName("example.com")
if err != nil {
log.Fatal(err)
}
// Fetch records of any type with name "foo.example.com"
// The name must be fully-qualified
foo := cloudflare.DNSRecord{Name: "foo.example.com"}
recs, err := api.DNSRecords(zoneID, foo)
if err != nil {
log.Fatal(err)
}
for _, r := range recs {
fmt.Printf("%s: %s\n", r.Name, r.Content)
}
}
func ExampleAPI_DNSRecords_filterByType() {
api, err := cloudflare.New("deadbeef", "[email protected]")
if err != nil {
log.Fatal(err)
}
zoneID, err := api.ZoneIDByName("example.com")
if err != nil {
log.Fatal(err)
}
// Fetch only AAAA type records
aaaa := cloudflare.DNSRecord{Type: "AAAA"}
recs, err := api.DNSRecords(zoneID, aaaa)
if err != nil {
log.Fatal(err)
}
for _, r := range recs {
fmt.Printf("%s: %s\n", r.Name, r.Content)
}
}