File: records.go

package info (click to toggle)
golang-github-denverdino-aliyungo 0.0~git20180921.13fa8aa-4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,824 kB
  • sloc: xml: 1,359; makefile: 3
file content (205 lines) | stat: -rw-r--r-- 4,377 bytes parent folder | download | duplicates (3)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package pvtz

import (
	"log"

	"github.com/denverdino/aliyungo/common"
)

type RecordStatus string

const EnableStatus = RecordStatus("ENABLE")
const DisableStatus = RecordStatus("DISABLE")

type DescribeZoneRecordsArgs struct {
	ZoneId       string
	Keyword      string
	Lang         string
	UserClientIp string
	common.Pagination
}

//
type ZoneRecordType struct {
	RecordId int64
	Rr       string
	Type     string
	Ttl      int
	Priority int
	Value    string
	Status   RecordStatus
}

type DescribeZoneRecordsResponse struct {
	common.Response
	common.PaginationResult
	Records struct {
		Record []ZoneRecordType
	}
}

// DescribeZoneRecords describes zones
//
// You can read doc at https://help.aliyun.com/document_detail/66252.html
func (client *Client) DescribeZoneRecords(args *DescribeZoneRecordsArgs) (records []ZoneRecordType, err error) {

	result := []ZoneRecordType{}

	for {
		response := DescribeZoneRecordsResponse{}
		err = client.Invoke("DescribeZoneRecords", args, &response)

		if err != nil {
			return result, err
		}

		result = append(result, response.Records.Record...)

		nextPage := response.PaginationResult.NextPage()
		if nextPage == nil {
			break
		}
		args.Pagination = *nextPage
	}

	return result, nil
}

func (client *Client) DescribeZoneRecordsByRR(zoneId string, rr string) (records []ZoneRecordType, err error) {
	records, err = client.DescribeZoneRecords(&DescribeZoneRecordsArgs{
		ZoneId:  zoneId,
		Keyword: rr,
	})

	if err != nil {
		return records, err
	}

	result := make([]ZoneRecordType, 0, 0)
	for _, record := range records {
		if record.Rr == rr {
			result = append(result, record)
		}
	}
	return result, err
}

func (client *Client) DeleteZoneRecordsByRR(zoneId string, rr string) error {
	records, err := client.DescribeZoneRecordsByRR(zoneId, rr)

	if err != nil {
		return err
	}

	for _, record := range records {
		if record.Rr == rr {
			err := client.DeleteZoneRecord(&DeleteZoneRecordArgs{
				RecordId: record.RecordId,
			})
			if err != nil {
				log.Printf("failed to delete zone record %d: %v\n", record.RecordId, err)
			}
		}
	}
	return nil
}

type AddZoneRecordArgs struct {
	ZoneName     string
	Rr           string
	Type         string
	Value        string
	ZoneId       string
	Lang         string
	Priority     int
	Ttl          int
	UserClientIp string
}

type AddZoneRecordResponse struct {
	common.Response
	Success  bool
	RecordId int64
}

// AddZoneRecord add zone record
//
// You can read doc at https://help.aliyun.com/document_detail/66248.html
func (client *Client) AddZoneRecord(args *AddZoneRecordArgs) (response *AddZoneRecordResponse, err error) {
	response = &AddZoneRecordResponse{}

	err = client.Invoke("AddZoneRecord", args, &response)

	return response, err
}

type UpdateZoneRecordArgs struct {
	RecordId     int64
	Rr           string
	Type         string
	Value        string
	Lang         string
	Priority     int
	Ttl          int
	UserClientIp string
}

type UpdateZoneRecordResponse struct {
	common.Response
	RecordId int64
}

// UpdateZoneRecord update zone record
//
// You can read doc at https://help.aliyun.com/document_detail/66250.html
func (client *Client) UpdateZoneRecord(args *AddZoneRecordArgs) (err error) {
	response := &UpdateZoneRecordResponse{}

	err = client.Invoke("UpdateZoneRecord", args, &response)

	return err
}

type DeleteZoneRecordArgs struct {
	RecordId     int64
	Lang         string
	UserClientIp string
}

type DeleteZoneRecordResponse struct {
	common.Response
	RecordId int64
}

// DeleteZone delete zone
//
// You can read doc at https://help.aliyun.com/document_detail/66249.html
func (client *Client) DeleteZoneRecord(args *DeleteZoneRecordArgs) (err error) {
	response := &DeleteZoneRecordResponse{}
	err = client.Invoke("DeleteZoneRecord", args, &response)

	return err
}

type SetZoneRecordStatusArgs struct {
	RecordId     int64
	Lang         string
	UserClientIp string
	Status       RecordStatus
}

type SetZoneRecordStatusResponse struct {
	common.Response
	RecordId string
	Status   RecordStatus
}

// SetZoneRecordStatus set zone record status
//
// You can read doc at https://help.aliyun.com/document_detail/66251.html
func (client *Client) SetZoneRecordStatus(args *SetZoneRecordStatusArgs) (err error) {
	response := &SetZoneRecordStatusResponse{}
	err = client.Invoke("SetZoneRecordStatus", args, &response)

	return err
}