-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.go
88 lines (56 loc) · 1.81 KB
/
api.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
// This package calls the GoDaddy API with a key and secret key for a specified (already existing domain).
package godaddy
import (
"io/ioutil"
"net/http"
"fmt"
"os"
)
// Get domain details. Return json results.
func GetDomains() string {
req, err := http.NewRequest("GET", os.ExpandEnv("https://api.godaddy.com/v1/domains/${DOMAIN}"), nil)
if err != nil {
// handle err
fmt.Printf("%s", err)
}
req.Header.Set("Authorization", os.ExpandEnv("sso-key ${API_KEY}:${API_SECRET}"))
resp, err := http.DefaultClient.Do(req)
bodyBytes, err2 := ioutil.ReadAll(resp.Body)
if err2 != nil {
fmt.Printf("%s", err2)
}
bodyString := string(bodyBytes)
//fmt.Printf("%s\n", string(bodyString))
if err != nil {
// handle err
fmt.Printf("%s", err)
}
defer resp.Body.Close()
return bodyString
}
// Get all records of type: A, AAAA, CNAME, TXT, and NS.
// return array of type string results.
func GetRecords() [5]string {
recordArr := [5]string{"A", "AAAA", "CNAME", "TXT", "NS"}
var resultArr [5]string
for i := 0; i <= len(recordArr)-1; i++ {
req, err := http.NewRequest("GET", os.ExpandEnv("https://api.godaddy.com/v1/domains/${DOMAIN}/records/" + recordArr[i]), nil)
if err != nil {
// handle err
fmt.Printf("%s", err)
}
req.Header.Set("Authorization", os.ExpandEnv("sso-key ${API_KEY}:${API_SECRET}"))
resp, err := http.DefaultClient.Do(req)
bodyBytes, err2 := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
if err2 != nil {
fmt.Printf("%s", err2)
}
resultArr[i] = string(bodyBytes)
if err != nil {
// handle err
fmt.Printf("%s", err)
}
}
return resultArr
}