-
Notifications
You must be signed in to change notification settings - Fork 11
/
domains.go
91 lines (76 loc) · 2.3 KB
/
domains.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
package clerk
import (
"fmt"
"net/http"
)
type DomainsService service
type DomainListResponse struct {
Data []Domain `json:"data"`
TotalCount int `json:"total_count"`
}
type DomainCNameTarget struct {
Host string `json:"host"`
Value string `json:"value"`
}
type Domain struct {
Object string `json:"object"`
ID string `json:"id"`
Name string `json:"name"`
IsSatellite bool `json:"is_satellite"`
FapiURL string `json:"frontend_api_url"`
AccountsPortalURL *string `json:"accounts_portal_url,omitempty"`
ProxyURL *string `json:"proxy_url,omitempty"`
CNameTargets []DomainCNameTarget `json:"cname_targets,omitempty"`
DevelopmentOrigin string `json:"development_origin"`
}
type CreateDomainParams struct {
Name string `json:"name"`
IsSatellite bool `json:"is_satellite"`
ProxyURL *string `json:"proxy_url,omitempty"`
}
type UpdateDomainParams struct {
Name *string `json:"name,omitempty"`
ProxyURL *string `json:"proxy_url,omitempty"`
}
func (s *DomainsService) ListAll() (*DomainListResponse, error) {
req, _ := s.client.NewRequest(http.MethodGet, DomainsURL)
var response *DomainListResponse
_, err := s.client.Do(req, &response)
if err != nil {
return nil, err
}
return response, nil
}
func (s *DomainsService) Create(
params CreateDomainParams,
) (*Domain, error) {
req, _ := s.client.NewRequest(http.MethodPost, DomainsURL, ¶ms)
var domain Domain
_, err := s.client.Do(req, &domain)
if err != nil {
return nil, err
}
return &domain, nil
}
func (s *DomainsService) Update(
domainID string,
params UpdateDomainParams,
) (*Domain, error) {
url := fmt.Sprintf("%s/%s", DomainsURL, domainID)
req, _ := s.client.NewRequest(http.MethodPatch, url, ¶ms)
var domain Domain
_, err := s.client.Do(req, &domain)
if err != nil {
return nil, err
}
return &domain, nil
}
func (s *DomainsService) Delete(domainID string) (*DeleteResponse, error) {
url := fmt.Sprintf("%s/%s", DomainsURL, domainID)
req, _ := s.client.NewRequest(http.MethodDelete, url)
var delResponse DeleteResponse
if _, err := s.client.Do(req, &delResponse); err != nil {
return nil, err
}
return &delResponse, nil
}