Debian Codegraph @

pvtz/records.go

raw symbols SCIP
1 package pvtz
2
3 import (
4 "log"
5
6 "github.com/denverdino/aliyungo/common"
7 )
8
9 type RecordStatus string
10
11 const EnableStatus = RecordStatus("ENABLE")
12 const DisableStatus = RecordStatus("DISABLE")
13
14 type DescribeZoneRecordsArgs struct {
15 ZoneId string
16 Keyword string
17 Lang string
18 UserClientIp string
19 common.Pagination
20 }
21
22 //
23 type ZoneRecordType struct {
24 RecordId int64
25 Rr string
26 Type string
27 Ttl int
28 Priority int
29 Value string
30 Status RecordStatus
31 }
32
33 type DescribeZoneRecordsResponse struct {
34 common.Response
35 common.PaginationResult
36 Records struct {
37 Record []ZoneRecordType
38 }
39 }
40
41 // DescribeZoneRecords describes zones
42 //
43 // You can read doc at https://help.aliyun.com/document_detail/66252.html
44 func (client *Client) DescribeZoneRecords(args *DescribeZoneRecordsArgs) (records []ZoneRecordType, err error) {
45
46 result := []ZoneRecordType{}
47
48 for {
49 response := DescribeZoneRecordsResponse{}
50 err = client.Invoke("DescribeZoneRecords", args, &response)
51
52 if err != nil {
53 return result, err
54 }
55
56 result = append(result, response.Records.Record...)
57
58 nextPage := response.PaginationResult.NextPage()
59 if nextPage == nil {
60 break
61 }
62 args.Pagination = *nextPage
63 }
64
65 return result, nil
66 }
67
68 func (client *Client) DescribeZoneRecordsByRR(zoneId string, rr string) (records []ZoneRecordType, err error) {
69 records, err = client.DescribeZoneRecords(&DescribeZoneRecordsArgs{
70 ZoneId: zoneId,
71 Keyword: rr,
72 })
73
74 if err != nil {
75 return records, err
76 }
77
78 result := make([]ZoneRecordType, 0, 0)
79 for _, record := range records {
80 if record.Rr == rr {
81 result = append(result, record)
82 }
83 }
84 return result, err
85 }
86
87 func (client *Client) DeleteZoneRecordsByRR(zoneId string, rr string) error {
88 records, err := client.DescribeZoneRecordsByRR(zoneId, rr)
89
90 if err != nil {
91 return err
92 }
93
94 for _, record := range records {
95 if record.Rr == rr {
96 err := client.DeleteZoneRecord(&DeleteZoneRecordArgs{
97 RecordId: record.RecordId,
98 })
99 if err != nil {
100 log.Printf("failed to delete zone record %d: %v\n", record.RecordId, err)
101 }
102 }
103 }
104 return nil
105 }
106
107 type AddZoneRecordArgs struct {
108 ZoneName string
109 Rr string
110 Type string
111 Value string
112 ZoneId string
113 Lang string
114 Priority int
115 Ttl int
116 UserClientIp string
117 }
118
119 type AddZoneRecordResponse struct {
120 common.Response
121 Success bool
122 RecordId int64
123 }
124
125 // AddZoneRecord add zone record
126 //
127 // You can read doc at https://help.aliyun.com/document_detail/66248.html
128 func (client *Client) AddZoneRecord(args *AddZoneRecordArgs) (response *AddZoneRecordResponse, err error) {
129 response = &AddZoneRecordResponse{}
130
131 err = client.Invoke("AddZoneRecord", args, &response)
132
133 return response, err
134 }
135
136 type UpdateZoneRecordArgs struct {
137 RecordId int64
138 Rr string
139 Type string
140 Value string
141 Lang string
142 Priority int
143 Ttl int
144 UserClientIp string
145 }
146
147 type UpdateZoneRecordResponse struct {
148 common.Response
149 RecordId int64
150 }
151
152 // UpdateZoneRecord update zone record
153 //
154 // You can read doc at https://help.aliyun.com/document_detail/66250.html
155 func (client *Client) UpdateZoneRecord(args *AddZoneRecordArgs) (err error) {
156 response := &UpdateZoneRecordResponse{}
157
158 err = client.Invoke("UpdateZoneRecord", args, &response)
159
160 return err
161 }
162
163 type DeleteZoneRecordArgs struct {
164 RecordId int64
165 Lang string
166 UserClientIp string
167 }
168
169 type DeleteZoneRecordResponse struct {
170 common.Response
171 RecordId int64
172 }
173
174 // DeleteZone delete zone
175 //
176 // You can read doc at https://help.aliyun.com/document_detail/66249.html
177 func (client *Client) DeleteZoneRecord(args *DeleteZoneRecordArgs) (err error) {
178 response := &DeleteZoneRecordResponse{}
179 err = client.Invoke("DeleteZoneRecord", args, &response)
180
181 return err
182 }
183
184 type SetZoneRecordStatusArgs struct {
185 RecordId int64
186 Lang string
187 UserClientIp string
188 Status RecordStatus
189 }
190
191 type SetZoneRecordStatusResponse struct {
192 common.Response
193 RecordId string
194 Status RecordStatus
195 }
196
197 // SetZoneRecordStatus set zone record status
198 //
199 // You can read doc at https://help.aliyun.com/document_detail/66251.html
200 func (client *Client) SetZoneRecordStatus(args *SetZoneRecordStatusArgs) (err error) {
201 response := &SetZoneRecordStatusResponse{}
202 err = client.Invoke("SetZoneRecordStatus", args, &response)
203
204 return err
205 }