* app: optimize config file reading

* read config file just once (even when upgrading)
* don't call os.Stat()
This commit is contained in:
Simon Zolin
2019-04-30 14:38:24 +03:00
parent 2dd6ea5161
commit 3ee8051e97
3 changed files with 36 additions and 38 deletions

31
app.go
View File

@@ -93,16 +93,17 @@ func run(args options) {
os.Exit(0)
}()
// Do the upgrade if necessary
err := upgradeConfig()
if err != nil {
log.Fatal(err)
}
if !config.firstRun {
// Do the upgrade if necessary
err := upgradeConfig()
if err != nil {
log.Fatal(err)
}
// parse from config file
err = parseConfig()
if err != nil {
log.Fatal(err)
err = parseConfig()
if err != nil {
os.Exit(1)
}
}
if (runtime.GOOS == "linux" || runtime.GOOS == "darwin") &&
@@ -120,10 +121,12 @@ func run(args options) {
loadFilters()
// Save the updated config
err = config.write()
if err != nil {
log.Fatal(err)
if !config.firstRun {
// Save the updated config
err := config.write()
if err != nil {
log.Fatal(err)
}
}
// Init the DNS server instance before registering HTTP handlers
@@ -131,7 +134,7 @@ func run(args options) {
initDNSServer(dnsBaseDir)
if !config.firstRun {
err = startDNSServer()
err := startDNSServer()
if err != nil {
log.Fatal(err)
}