forked from cloudflare/cloudflare-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
page_rules_example_test.go
109 lines (91 loc) · 1.83 KB
/
page_rules_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
101
102
103
104
105
106
107
108
109
package cloudflare_test
import (
"fmt"
"log"
cloudflare "github.com/cloudflare/cloudflare-go"
)
var exampleNewPageRule = cloudflare.PageRule{
Actions: []cloudflare.PageRuleAction{
{
ID: "always_online",
Value: "on",
},
{
ID: "ssl",
Value: "flexible",
},
},
Targets: []cloudflare.PageRuleTarget{
{
Target: "url",
Constraint: struct {
Operator string "json:\"operator\""
Value string "json:\"value\""
}{Operator: "matches", Value: fmt.Sprintf("example.%s", domain)},
},
},
Priority: 1,
Status: "active",
}
func ExampleAPI_CreatePageRule() {
api, err := cloudflare.New(apiKey, user)
if err != nil {
log.Fatal(err)
}
zoneID, err := api.ZoneIDByName(domain)
if err != nil {
log.Fatal(err)
}
pageRule, err := api.CreatePageRule(zoneID, exampleNewPageRule)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%+v\n", pageRule)
}
func ExampleAPI_ListPageRules() {
api, err := cloudflare.New(apiKey, user)
if err != nil {
log.Fatal(err)
}
zoneID, err := api.ZoneIDByName(domain)
if err != nil {
log.Fatal(err)
}
pageRules, err := api.ListPageRules(zoneID)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%+v\n", pageRules)
for _, r := range pageRules {
fmt.Printf("%+v\n", r)
}
}
func ExampleAPI_PageRule() {
api, err := cloudflare.New(apiKey, user)
if err != nil {
log.Fatal(err)
}
zoneID, err := api.ZoneIDByName(domain)
if err != nil {
log.Fatal(err)
}
pageRules, err := api.PageRule(zoneID, "my_page_rule_id")
if err != nil {
log.Fatal(err)
}
fmt.Printf("%+v\n", pageRules)
}
func ExampleAPI_DeletePageRule() {
api, err := cloudflare.New(apiKey, user)
if err != nil {
log.Fatal(err)
}
zoneID, err := api.ZoneIDByName(domain)
if err != nil {
log.Fatal(err)
}
err = api.DeletePageRule(zoneID, "my_page_rule_id")
if err != nil {
log.Fatal(err)
}
}