diff options
| author | Shulhan <m.shulhan@gmail.com> | 2020-07-25 02:39:33 +0700 |
|---|---|---|
| committer | Shulhan <m.shulhan@gmail.com> | 2020-07-26 03:48:51 +0700 |
| commit | 954a8f071deff27d0434027e4787e72fbd7880d4 (patch) | |
| tree | 9c77cef7ba8edcaaee18b5b629ffae29ce04015c /rescached.go | |
| parent | 53918e8b3fc8a68f7f88e6ece0706e1ae049a8e5 (diff) | |
| download | rescached-954a8f071deff27d0434027e4787e72fbd7880d4.tar.xz | |
all: implement UI to create, update, delete hosts file in hosts.d
The UI will update (insert or remove) the records on cache on the fly.
Diffstat (limited to 'rescached.go')
| -rw-r--r-- | rescached.go | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/rescached.go b/rescached.go index 3aab17a..6a74946 100644 --- a/rescached.go +++ b/rescached.go @@ -26,7 +26,6 @@ type Server struct { httpd *http.Server httpdRunner sync.Once - hostsFiles map[string]*dns.HostsFile masterFiles map[string]*dns.MasterFile } @@ -41,8 +40,9 @@ func New(fileConfig string) (srv *Server, err error) { } srv = &Server{ - fileConfig: fileConfig, - env: env, + fileConfig: fileConfig, + env: env, + masterFiles: make(map[string]*dns.MasterFile), } err = srv.httpdInit() @@ -63,19 +63,21 @@ func (srv *Server) Start() (err error) { return err } - hostsFile, err := dns.ParseHostsFile(dns.GetSystemHosts()) + dnsHostsFile, err := dns.ParseHostsFile(dns.GetSystemHosts()) if err != nil { return err } - srv.dns.PopulateCaches(hostsFile.Messages) + srv.dns.PopulateCaches(dnsHostsFile.Messages) - srv.hostsFiles, err = dns.LoadHostsDir(dirHosts) + dnsHostsFiles, err := dns.LoadHostsDir(dirHosts) if err != nil { return err } - for _, hostsFile := range srv.hostsFiles { - srv.dns.PopulateCaches(hostsFile.Messages) + for _, dnsHostsFile := range dnsHostsFiles { + srv.dns.PopulateCaches(dnsHostsFile.Messages) + srv.env.HostsFiles = append(srv.env.HostsFiles, + convertHostsFile(dnsHostsFile)) } srv.masterFiles, err = dns.LoadMasterDir(dirMaster) |
