moved some stuff from main into own func
This commit is contained in:
parent
f0eca13294
commit
644e0ce398
80
coolDns.go
80
coolDns.go
@ -76,6 +76,47 @@ var anyRecordTypes = []uint16{
|
||||
dns.TypeCAA,
|
||||
}
|
||||
|
||||
func start(configPath string) {
|
||||
config, err := loadConfig(configPath)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to load config: %s\n", err.Error())
|
||||
}
|
||||
|
||||
err = os.Chdir(filepath.Dir(configPath))
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to goto config dir: %s", err.Error())
|
||||
}
|
||||
|
||||
zones, err := loadZones(config.Zones)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to load zones: %s\n", err.Error())
|
||||
}
|
||||
|
||||
aclList, err := createACLList(config.ACL)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to parse ACL rules: %s\n", err.Error())
|
||||
}
|
||||
|
||||
blacklist := loadBlacklist(config.Blacklist)
|
||||
|
||||
var acmeMap *legoMap
|
||||
if config.Lego.Enable {
|
||||
acmeMap = startLEGOWebSever(config.Lego)
|
||||
}
|
||||
|
||||
server := createServer(zones, *config, aclList, blacklist, acmeMap)
|
||||
|
||||
listenAndServer(server, config.Address)
|
||||
|
||||
if config.TLS.Enable {
|
||||
listenAndServerTLS(server, config.TLS.Address, config.TLS.Cert, config.TLS.Key)
|
||||
|
||||
log.Printf("Start listening on tcp %s for tls", config.TLS.Address)
|
||||
}
|
||||
|
||||
log.Printf("Start listening on udp %s and tcp %s\n", config.Address, config.Address)
|
||||
}
|
||||
|
||||
func loadConfig(configPath string) (*config, error) {
|
||||
file, err := ioutil.ReadFile(configPath)
|
||||
if err != nil {
|
||||
@ -384,44 +425,7 @@ func main() {
|
||||
configPath := flag.String("c", "/etc/cool-dns/config.yaml", "path to the config file")
|
||||
flag.Parse()
|
||||
|
||||
config, err := loadConfig(*configPath)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to load config: %s\n", err.Error())
|
||||
}
|
||||
|
||||
err = os.Chdir(filepath.Dir(*configPath))
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to goto config dir: %s", err.Error())
|
||||
}
|
||||
|
||||
zones, err := loadZones(config.Zones)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to load zones: %s\n", err.Error())
|
||||
}
|
||||
|
||||
aclList, err := createACLList(config.ACL)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to parse ACL rules: %s\n", err.Error())
|
||||
}
|
||||
|
||||
blacklist := loadBlacklist(config.Blacklist)
|
||||
|
||||
var acmeMap *legoMap
|
||||
if config.Lego.Enable {
|
||||
acmeMap = startLEGOWebSever(config.Lego)
|
||||
}
|
||||
|
||||
server := createServer(zones, *config, aclList, blacklist, acmeMap)
|
||||
|
||||
listenAndServer(server, config.Address)
|
||||
|
||||
if config.TLS.Enable {
|
||||
listenAndServerTLS(server, config.TLS.Address, config.TLS.Cert, config.TLS.Key)
|
||||
|
||||
log.Printf("Start listening on tcp %s for tls", config.TLS.Address)
|
||||
}
|
||||
|
||||
log.Printf("Start listening on udp %s and tcp %s\n", config.Address, config.Address)
|
||||
start(*configPath)
|
||||
|
||||
sig := make(chan os.Signal)
|
||||
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
Loading…
Reference in New Issue
Block a user