-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdnsapi.go
More file actions
43 lines (38 loc) · 784 Bytes
/
dnsapi.go
File metadata and controls
43 lines (38 loc) · 784 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
// sdnsweb communication with sdns servers.
package main
import (
"errors"
"fmt"
"io/ioutil"
"net/http"
)
func dnsRegCall(url string) error {
resp, err := http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
strbody := string(body)
if strbody != "ok" {
return errors.New(strbody)
}
return nil
}
func dnsRegisterDomain(domain, dstIP string) error {
var ret error
for _, server := range config.dnsAPIServers {
url := fmt.Sprintf("http://%s/set/host/%s/%s/%s/", server, config.httpApiKey, domain, dstIP)
err := dnsRegCall(url)
if err != nil {
ret = err
}
}
return ret
}
func dnsUpdateDomain(domain, dstIP string) error {
return dnsRegisterDomain(domain, dstIP)
}