Make host records refresh interval be configurable
This commit is contained in:
parent
8e14764aa7
commit
8492d8c679
@ -45,4 +45,6 @@ host-file = "/etc/hosts"
|
||||
redis-enable = false
|
||||
redis-key = "godns:hosts"
|
||||
ttl = 600
|
||||
refresh-interval = 5 # 5 seconds
|
||||
|
||||
|
||||
|
5
hosts.go
5
hosts.go
@ -15,6 +15,7 @@ import (
|
||||
type Hosts struct {
|
||||
fileHosts *FileHosts
|
||||
redisHosts *RedisHosts
|
||||
refreshInterval time.Duration
|
||||
}
|
||||
|
||||
func NewHosts(hs HostsSettings, rs RedisSettings) Hosts {
|
||||
@ -33,7 +34,7 @@ func NewHosts(hs HostsSettings, rs RedisSettings) Hosts {
|
||||
}
|
||||
}
|
||||
|
||||
hosts := Hosts{fileHosts, redisHosts}
|
||||
hosts := Hosts{fileHosts, redisHosts, time.Second * time.Duration(hs.RefreshInterval)}
|
||||
hosts.refresh()
|
||||
return hosts
|
||||
|
||||
@ -80,7 +81,7 @@ func (h *Hosts) Get(domain string, family int) ([]net.IP, bool) {
|
||||
Update hosts records from /etc/hosts file and redis per minute
|
||||
*/
|
||||
func (h *Hosts) refresh() {
|
||||
ticker := time.NewTicker(time.Second * 5)
|
||||
ticker := time.NewTicker(h.refreshInterval)
|
||||
go func() {
|
||||
for {
|
||||
h.fileHosts.Refresh()
|
||||
|
@ -80,6 +80,7 @@ type HostsSettings struct {
|
||||
RedisEnable bool `toml:"redis-enable"`
|
||||
RedisKey string `toml:"redis-key"`
|
||||
TTL uint32 `toml:"ttl"`
|
||||
RefreshInterval uint32 `toml:"refresh-interval"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
Loading…
Reference in New Issue
Block a user