Factor out LoadConfig

This commit is contained in:
George 2020-09-22 07:48:23 -04:00 committed by George
parent f7dbafe774
commit 8052e6c080
2 changed files with 14 additions and 12 deletions

View File

@ -28,6 +28,14 @@ func parseNetworks(networksconf string) (map[string]*net.IPNet, error) {
return networks, nil
}
func loadConfig(s *meshname.MeshnameServer, confPath string) error {
zoneConf, err := meshname.ParseConfigFile(confPath)
if err == nil {
s.SetZoneConfig(zoneConf)
}
return err
}
var (
genconf, subdomain, useconffile, listenAddr, networksconf string
debug bool
@ -75,7 +83,9 @@ func main() {
}
if useconffile != "" {
s.LoadConfig(useconffile)
if err := loadConfig(s, useconffile); err != nil {
logger.Errorln(err)
}
}
s.Start()
@ -91,7 +101,9 @@ func main() {
return
case _ = <-r:
if useconffile != "" {
s.LoadConfig(useconffile)
if err := loadConfig(s, useconffile); err != nil {
logger.Errorln(err)
}
}
}
}

View File

@ -68,16 +68,6 @@ func (s *MeshnameServer) Start() error {
}
}
func (s *MeshnameServer) LoadConfig(confPath string) {
if zoneConf, err := ParseConfigFile(confPath); err == nil {
s.zoneConfigLock.Lock()
s.zoneConfig = zoneConf
s.zoneConfigLock.Unlock()
} else {
s.log.Errorln("Can't parse config file:", err)
}
}
func (s *MeshnameServer) SetZoneConfig(zoneConfig map[string][]dns.RR) {
s.zoneConfigLock.Lock()
s.zoneConfig = zoneConfig