-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto_renewal.go
44 lines (37 loc) · 972 Bytes
/
auto_renewal.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
package main
import (
"encoding/json"
"log"
"net/http"
)
type AutoRenew struct {
ID int `json:"id"`
Domain string `json:"unicode_name"`
Lockable bool
AutoRenew bool `json:"auto_renew"`
}
func enableAutoRenewal(domain string, enabled bool) {
isDomainEmpty(domain)
var url string
var r *http.Request
// Enable/Disable auto renewal
if enabled {
url = config.ApiURL + "/domains/" + config.Domain + "/auto_renewal"
r = setHeaders("POST", url, nil)
} else {
url = config.ApiURL + "/domains/" + config.Domain + "/auto_renewal"
r = setHeaders("DELETE", url, nil)
}
httpClient := http.Client{}
response, err := httpClient.Do(r)
if err != nil {
log.Fatal("AutoRenewal-HTTPClient: ", err)
}
defer response.Body.Close()
dataResponse := make(map[string]AutoRenew)
err = json.NewDecoder(response.Body).Decode(&dataResponse)
if err != nil {
log.Fatal("enableAutoRenewal-Decode: ", err)
}
stdoutAutoRenew(dataResponse["domain"])
}