-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathservice.go
More file actions
47 lines (39 loc) · 877 Bytes
/
service.go
File metadata and controls
47 lines (39 loc) · 877 Bytes
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
package main
import (
"io/ioutil"
"net/http"
)
//Ddns represents a dynamic DNS service
type Ddns struct {
Name string
Domain string
UserName string
Password string
Token string
}
//DdnsService represents an interface for a dynamic DNS service
type DdnsService interface {
updateIP() error
getDomain() string
}
//GetResponse returns the content at the url address
func GetResponse(url string, login string, password string) (string, error) {
request, err := http.NewRequest("GET", url, nil)
if err != nil {
return "", err
}
if login != "" && password != "" {
request.SetBasicAuth(login, password)
}
client := &http.Client{}
response, err := client.Do(request)
if err != nil {
return "", err
}
defer response.Body.Close()
content, err := ioutil.ReadAll(response.Body)
if err != nil {
return "", err
}
return string(content), nil
}