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-enable = false
|
||||||
redis-key = "godns:hosts"
|
redis-key = "godns:hosts"
|
||||||
ttl = 600
|
ttl = 600
|
||||||
|
refresh-interval = 5 # 5 seconds
|
||||||
|
|
||||||
|
|
||||||
|
9
hosts.go
9
hosts.go
@ -13,8 +13,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Hosts struct {
|
type Hosts struct {
|
||||||
fileHosts *FileHosts
|
fileHosts *FileHosts
|
||||||
redisHosts *RedisHosts
|
redisHosts *RedisHosts
|
||||||
|
refreshInterval time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHosts(hs HostsSettings, rs RedisSettings) Hosts {
|
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()
|
hosts.refresh()
|
||||||
return hosts
|
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
|
Update hosts records from /etc/hosts file and redis per minute
|
||||||
*/
|
*/
|
||||||
func (h *Hosts) refresh() {
|
func (h *Hosts) refresh() {
|
||||||
ticker := time.NewTicker(time.Second * 5)
|
ticker := time.NewTicker(h.refreshInterval)
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
h.fileHosts.Refresh()
|
h.fileHosts.Refresh()
|
||||||
|
11
settings.go
11
settings.go
@ -75,11 +75,12 @@ type CacheSettings struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type HostsSettings struct {
|
type HostsSettings struct {
|
||||||
Enable bool
|
Enable bool
|
||||||
HostsFile string `toml:"host-file"`
|
HostsFile string `toml:"host-file"`
|
||||||
RedisEnable bool `toml:"redis-enable"`
|
RedisEnable bool `toml:"redis-enable"`
|
||||||
RedisKey string `toml:"redis-key"`
|
RedisKey string `toml:"redis-key"`
|
||||||
TTL uint32 `toml:"ttl"`
|
TTL uint32 `toml:"ttl"`
|
||||||
|
RefreshInterval uint32 `toml:"refresh-interval"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
Loading…
Reference in New Issue
Block a user