From 21ea4f905f3a0d4f5fca22d50112aae1b1681375 Mon Sep 17 00:00:00 2001 From: Timothy Date: Tue, 13 May 2014 23:24:19 +0800 Subject: [PATCH] add the infinite loop --- godns.go | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/godns.go b/godns.go index dc107bb..0f8b2ce 100644 --- a/godns.go +++ b/godns.go @@ -28,25 +28,27 @@ func main() { } func dns_loop(loop chan bool) { - fmt.Println("Inside the loop...") - time.Sleep(time.Second * 2) - domain_id := get_domain(Configuration.Domain) + for { - currentIP, _ := get_currentIP(Configuration.IP_Url) - sub_domain_id, ip := get_subdomain(domain_id, Configuration.Sub_domain) + domain_id := get_domain(Configuration.Domain) - fmt.Printf("currentIp is:%s\n", currentIP) + currentIP, _ := get_currentIP(Configuration.IP_Url) + sub_domain_id, ip := get_subdomain(domain_id, Configuration.Sub_domain) - //Continue to check the IP of sub-domain - if len(ip) > 0 && !strings.Contains(currentIP, ip) { + fmt.Printf("currentIp is:%s\n", currentIP) - fmt.Println("Start to update record IP...") - update_ip(domain_id, sub_domain_id, Configuration.Sub_domain, currentIP) + //Continue to check the IP of sub-domain + if len(ip) > 0 && !strings.Contains(currentIP, ip) { - } else { - fmt.Println("Current IP is same as domain IP, no need to update...") + fmt.Println("Start to update record IP...") + update_ip(domain_id, sub_domain_id, Configuration.Sub_domain, currentIP) + + } else { + fmt.Println("Current IP is same as domain IP, no need to update...") + } + + //Interval is 5 minutes + time.Sleep(time.Second * 60 * 5) } - - loop <- false }