-
Notifications
You must be signed in to change notification settings - Fork 7
/
domain.go
82 lines (54 loc) · 1.82 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
package vscale_api_go
import (
"encoding/json"
"fmt"
"net/http"
"strconv"
)
type DomainService struct {
client Client
}
type Domain struct {
ID int64 `json:"id,omitempty"`
ChangeDate int64 `json:"change_date,omitempty"`
CreateDate int64 `json:"create_date,omitempty"`
Name string `json:"name,omitempty"`
Tags []DomainTag `json:"tags,omitempty"`
UserID int64 `json:"user_id,omitempty"`
}
func (d *DomainService) List() (*[]Domain, *http.Response, error) {
domains := new([]Domain)
res, err := d.client.ExecuteRequest("GET", "domains/", []byte{}, domains)
return domains, res, err
}
func (d *DomainService) Create(name string) (*Domain, *http.Response, error) {
// TODO Add bind zone
domain := new(Domain)
body := struct {
Name string `json:"name,omitempty"`
}{name}
b, _ := json.Marshal(body)
res, err := d.client.ExecuteRequest("POST", "domains/", b, domain)
return domain, res, err
}
func (d *DomainService) Get(domainID int64) (*Domain, *http.Response, error) {
domain := new(Domain)
res, err := d.client.ExecuteRequest("GET", fmt.Sprint("domains/", strconv.FormatInt(domainID, 10)), []byte{}, domain)
return domain, res, err
}
func (d *DomainService) Update(domainID int64, tags []int64) (*Domain, *http.Response, error) {
domain := new(Domain)
body := struct {
Tags []int64 `json:"tags,omitempty"`
}{tags}
b, _ := json.Marshal(body)
res, err := d.client.ExecuteRequest("PATCH", fmt.Sprint("domains/", strconv.FormatInt(domainID, 10)), b, domain)
return domain, res, err
}
func (d *DomainService) Remove(domainID int64) (bool, *http.Response, error) {
res, err := d.client.ExecuteRequest("DELETE", fmt.Sprint("domains/", strconv.FormatInt(domainID, 10)), []byte{}, struct{}{})
if err != nil {
return false, res, err
}
return true, res, err
}