-
Notifications
You must be signed in to change notification settings - Fork 4
/
domain.go
109 lines (93 loc) · 2.33 KB
/
domain.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 cns
import (
"net/url"
"strconv"
)
//“域名”的数据结构
type Domain struct {
Id int
Status string
GroupId string `json:"group_id"`
SearchenginePush string `json:"searchengine_push"`
IsMark string `json:"is_mark"`
Ttl string
CnameSpeedup string `json:"cname_speedup"`
Remark string
CreatedOn string `json:"created_on"`
UpdatedOn string `json:"updated_on"`
QProjectId int `json:"q_project_id"`
Punycode string
ExtStatus string `json:"ext_status"`
SrcFlag string `json:"src_flag"`
Name string
Grade string `json:"DP_Free"`
GradeTitle string `json:"grade_title"`
IsVip string `json:"is_vip"`
Owner string
Records string
MinTtl int `json:"min_ttl"`
}
//获取域名列表
func (cli *Client) DomainList() ([]Domain, error) {
var respInfo struct {
BaseResponse
Data struct {
Info struct {
DomainTotal int `json:"domain_total"`
}
Domains []Domain
}
}
err := cli.requestGET("DomainList", nil, &respInfo)
if err != nil {
return nil, err
}
return respInfo.Data.Domains, nil
}
//添加域名,如果成功,返回创建的域名ID
func (cli *Client) DomainCreate(domain string, projectId ...int) (int, error) {
param := url.Values{"domain": {domain}}
if len(projectId) > 0 {
param.Set("projectId", strconv.Itoa(projectId[0]))
}
var respInfo struct {
BaseResponse
Data struct {
Domain struct {
Id int `json:",string"`
Punycode string
Domain string
}
}
}
err := cli.requestGET("DomainCreate", param, &respInfo)
if err != nil {
return 0, err
}
return respInfo.Data.Domain.Id, nil
}
//设置域名解析状态
func (cli *Client) SetDomainStatus(domain string, enable bool) error {
param := url.Values{"domain": {domain}}
if enable {
param.Set("status", "enable")
} else {
param.Set("status", "disable")
}
var respInfo BaseResponse
err := cli.requestGET("SetDomainStatus", param, &respInfo)
if err != nil {
return err
}
return nil
}
//删除域名
func (cli *Client) DomainDelete(domain string) error {
param := url.Values{"domain": {domain}}
var respInfo BaseResponse
err := cli.requestGET("DomainDelete", param, &respInfo)
if err != nil {
return err
}
return nil
}