-
Notifications
You must be signed in to change notification settings - Fork 0
/
domain.go
52 lines (41 loc) · 1017 Bytes
/
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
package atomx
import (
"bytes"
"encoding/json"
"net/http"
)
type Domain struct {
ID int64 `json:"id"`
Name string `json:"name,omitempty"`
CategoryID int64 `json:"category,omitempty"`
Attributes DomainAttributes `json:"attributes,omitempty"`
}
func (c *Client) PostDomains(body string) ([]Domain, error) {
data, err := json.Marshal(body)
if err != nil {
return nil, err
}
req, err := http.NewRequest("POST", c.ApiURL+"domains", bytes.NewReader(data))
if err != nil {
return nil, err
}
req.Header.Add("Content-Type", "application/json")
res, err := c.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
var resp struct {
Success bool `json:"success"`
Error string `json:"error"`
Domains []Domain `json:"domains"`
}
dec := json.NewDecoder(res.Body)
if err := dec.Decode(&resp); err != nil {
return nil, err
}
if !resp.Success {
return nil, &ApiError{Message: resp.Error}
}
return resp.Domains, nil
}