-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_ip.go
49 lines (40 loc) · 866 Bytes
/
update_ip.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
package main
import (
"log"
"net/http"
)
func updateIP(host, domain, password string) error {
req, err := createRequest(host, domain, password)
if err != nil {
return err
}
return sendRequest(req)
}
func createRequest(host, domain, password string) (*http.Request, error) {
req, err := http.NewRequest("GET", "https://dynamicdns.park-your-domain.com/update", nil)
if err != nil {
return nil, err
}
q := req.URL.Query()
q.Add("host", host)
q.Add("domain", domain)
q.Add("password", password)
req.URL.RawQuery = q.Encode()
return req, nil
}
func sendRequest(req *http.Request) error {
resp, err := http.DefaultClient.Do(req)
if err != nil {
return err
}
defer func() {
if err := resp.Body.Close(); err != nil {
log.Println("ERROR", err)
}
}()
result, err := parse(resp.Body)
if err != nil {
return err
}
return result
}