-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (42 loc) · 1.2 KB
/
main.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 (
"flag"
"fmt"
"strings"
common "github.com/plkumar/gddns/common"
config "github.com/plkumar/gddns/config"
"github.com/plkumar/gddns/ddns"
)
func main() {
fmt.Println("Google Dynamic DNS Client")
standalone := flag.Bool("standalone", true, "Run in standalone mode.")
configFile := flag.String("config", "gddns.yml", "configuration file path.")
flag.Parse()
if *standalone {
y, err := config.GetConfig(*configFile)
if err == nil {
gd := ddns.GoogleDDNS{}
for key, host := range y.Gddns {
fmt.Println("Updating for: ", key)
hostParams := host["params"]
gd.SetHost(&hostParams)
status, err := gd.UpdateDDNSIp()
if err != nil {
fmt.Println(err.Error())
} else {
if strings.Contains(status, "success") {
fmt.Println("DNS Updated successfully.")
} else if strings.Contains(status, "nochg") {
fmt.Println("No Change")
} else {
// DNS Update failed, log and stop processing current host
// TODO: Stop further DNS update attempts to ensure google is not blocking the client
fmt.Println(status, common.DDNSStatusMap[status])
}
}
}
} else {
fmt.Println("Error reading configuration :: ", err)
}
}
}