From 04134b20a465e0f3df8c78bbc856ac40c52e406b Mon Sep 17 00:00:00 2001 From: TimothyYe Date: Sun, 21 Apr 2019 17:18:05 +0800 Subject: [PATCH] make interval configurable --- config_sample.json | 1 + handler/alidns/alidns_handler.go | 6 +++--- handler/cloudflare/cloudflare_handler.go | 6 +++--- handler/dnspod/dnspod_handler.go | 6 +++--- handler/he/he_handler.go | 6 +++--- settings.go | 6 ++++++ utils.go | 2 -- 7 files changed, 19 insertions(+), 14 deletions(-) diff --git a/config_sample.json b/config_sample.json index d2bcb19..b25e1ae 100644 --- a/config_sample.json +++ b/config_sample.json @@ -19,6 +19,7 @@ } ], "ip_url": "https://myip.biturl.top", + "interval": 300, "ip_interface": "eth0", "socks5_proxy": "", "notify": { diff --git a/handler/alidns/alidns_handler.go b/handler/alidns/alidns_handler.go index 5dd2cf7..94c63af 100644 --- a/handler/alidns/alidns_handler.go +++ b/handler/alidns/alidns_handler.go @@ -71,9 +71,9 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns. } } } - // Interval is 5 minutes - log.Printf("Going to sleep, will start next checking in %d minutes...\r\n", godns.INTERVAL) - time.Sleep(time.Minute * godns.INTERVAL) + // Sleep with interval + log.Printf("Going to sleep, will start next checking in %d seconds...\r\n", handler.Configuration.Interval) + time.Sleep(time.Second * time.Duration(handler.Configuration.Interval)) } } diff --git a/handler/cloudflare/cloudflare_handler.go b/handler/cloudflare/cloudflare_handler.go index f3908cb..40f2e7f 100644 --- a/handler/cloudflare/cloudflare_handler.go +++ b/handler/cloudflare/cloudflare_handler.go @@ -119,9 +119,9 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns. log.Println("Failed to find zone for domain:", domain.DomainName) } } - // Interval is 5 minutes - log.Printf("Going to sleep, will start next checking in %d minutes...\r\n", godns.INTERVAL) - time.Sleep(time.Minute * godns.INTERVAL) + // Sleep with interval + log.Printf("Going to sleep, will start next checking in %d seconds...\r\n", handler.Configuration.Interval) + time.Sleep(time.Second * time.Duration(handler.Configuration.Interval)) } } diff --git a/handler/dnspod/dnspod_handler.go b/handler/dnspod/dnspod_handler.go index 130c8df..31e8277 100644 --- a/handler/dnspod/dnspod_handler.go +++ b/handler/dnspod/dnspod_handler.go @@ -86,9 +86,9 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns. } } } - // Interval is 5 minutes - log.Printf("Going to sleep, will start next checking in %d minutes...\r\n", godns.INTERVAL) - time.Sleep(time.Minute * godns.INTERVAL) + // Sleep with interval + log.Printf("Going to sleep, will start next checking in %d seconds...\r\n", handler.Configuration.Interval) + time.Sleep(time.Second * time.Duration(handler.Configuration.Interval)) } } diff --git a/handler/he/he_handler.go b/handler/he/he_handler.go index 15e477c..303aada 100644 --- a/handler/he/he_handler.go +++ b/handler/he/he_handler.go @@ -68,9 +68,9 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns. } } } - // Interval is 5 minutes - log.Printf("Going to sleep, will start next checking in %d minutes...\r\n", godns.INTERVAL) - time.Sleep(time.Minute * godns.INTERVAL) + // Sleep with interval + log.Printf("Going to sleep, will start next checking in %d seconds...\r\n", handler.Configuration.Interval) + time.Sleep(time.Second * time.Duration(handler.Configuration.Interval)) } } diff --git a/settings.go b/settings.go index 897e91b..40ab6f7 100644 --- a/settings.go +++ b/settings.go @@ -30,6 +30,7 @@ type Settings struct { LoginToken string `json:"login_token"` Domains []Domain `json:"domains"` IPUrl string `json:"ip_url"` + Interval int `json:"interval"` LogPath string `json:"log_path"` Socks5Proxy string `json:"socks5_proxy"` Notify Notify `json:"notify"` @@ -53,5 +54,10 @@ func LoadSettings(configPath string, settings *Settings) error { return err } + if settings.Interval == 0 { + // set default interval as 5 minutes if interval is 0 + settings.Interval = 5 * 60 + } + return nil } diff --git a/utils.go b/utils.go index 536922a..4f202a0 100644 --- a/utils.go +++ b/utils.go @@ -34,8 +34,6 @@ https://github.com/TimothyYe/godns const ( // PanicMax is the max allowed panic times PanicMax = 5 - // INTERVAL is minute - INTERVAL = 5 // DNSPOD for dnspod.cn DNSPOD = "DNSPod" // HE for he.net