forked from cloudflare/cloudflare-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdns_example_test.go
94 lines (76 loc) · 2.03 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
package cloudflare_test
import (
"context"
"fmt"
"log"
"github.com/cloudflare/cloudflare-go"
)
func ExampleAPI_ListDNSRecords_all() {
api, err := cloudflare.New("deadbeef", "test@example.org")
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.ListDNSRecords(context.Background(), cloudflare.ZoneIdentifier(zoneID), cloudflare.ListDNSRecordsParams{})
if err != nil {
log.Fatal(err)
}
for _, r := range recs {
fmt.Printf("%s: %s\n", r.Name, r.Content)
}
}
func ExampleAPI_ListDNSRecords_filterByContent() {
api, err := cloudflare.New("deadbeef", "test@example.org")
if err != nil {
log.Fatal(err)
}
zoneID, err := api.ZoneIDByName("example.com")
if err != nil {
log.Fatal(err)
}
recs, _, err := api.ListDNSRecords(context.Background(), cloudflare.ZoneIdentifier(zoneID), cloudflare.ListDNSRecordsParams{Content: "198.51.100.1"})
if err != nil {
log.Fatal(err)
}
for _, r := range recs {
fmt.Printf("%s: %s\n", r.Name, r.Content)
}
}
func ExampleAPI_ListDNSRecords_filterByName() {
api, err := cloudflare.New("deadbeef", "test@example.org")
if err != nil {
log.Fatal(err)
}
zoneID, err := api.ZoneIDByName("example.com")
if err != nil {
log.Fatal(err)
}
recs, _, err := api.ListDNSRecords(context.Background(), cloudflare.ZoneIdentifier(zoneID), cloudflare.ListDNSRecordsParams{Name: "foo.example.com"})
if err != nil {
log.Fatal(err)
}
for _, r := range recs {
fmt.Printf("%s: %s\n", r.Name, r.Content)
}
}
func ExampleAPI_ListDNSRecords_filterByType() {
api, err := cloudflare.New("deadbeef", "test@example.org")
if err != nil {
log.Fatal(err)
}
zoneID, err := api.ZoneIDByName("example.com")
if err != nil {
log.Fatal(err)
}
recs, _, err := api.ListDNSRecords(context.Background(), cloudflare.ZoneIdentifier(zoneID), cloudflare.ListDNSRecordsParams{Type: "AAAA"})
if err != nil {
log.Fatal(err)
}
for _, r := range recs {
fmt.Printf("%s: %s\n", r.Name, r.Content)
}
}