* stats: refactor: move HTTP handlers to stats/

DNS module passes additional parameters to Stats module.
This allows Stats to handle HTTP requests by itself - completely removing
 all stats-related code from outside.
This commit is contained in:
Simon Zolin
2019-09-25 15:36:09 +03:00
parent 407917241a
commit bbb5413331
9 changed files with 162 additions and 126 deletions

View File

@@ -21,6 +21,11 @@ type dnsContext struct {
whois *Whois
}
// Called by other modules when configuration is changed
func onConfigModified() {
_ = config.write()
}
// initDNSServer creates an instance of the dnsforward.Server
// Please note that we must do it even if we don't start it
// so that we had access to the query log and the stats
@@ -31,8 +36,10 @@ func initDNSServer(baseDir string) {
}
statsConf := stats.Config{
Filename: filepath.Join(baseDir, "stats.db"),
LimitDays: config.DNS.StatsInterval,
Filename: filepath.Join(baseDir, "stats.db"),
LimitDays: config.DNS.StatsInterval,
ConfigModified: onConfigModified,
HTTPRegister: httpRegister,
}
config.stats, err = stats.New(statsConf)
if err != nil {