summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-06-11 05:13:10 -0400
committerBen Morrison <ben@gbmor.dev>2019-06-11 05:13:10 -0400
commit42a3e8afa88e8b59f4c41b77050a24341fb76a55 (patch)
tree8ec78c0a82865c6eb3a2ae47e861e9d737632ea1
parentfb328631e55830f3a2cab79bf18115324910c93c (diff)
downloadgetwtxt-42a3e8afa88e8b59f4c41b77050a24341fb76a55.tar.gz
readability changes
-rw-r--r--svc/conf.go46
-rw-r--r--svc/init.go7
2 files changed, 21 insertions, 32 deletions
diff --git a/svc/conf.go b/svc/conf.go
index 2e9d671..90cac6a 100644
--- a/svc/conf.go
+++ b/svc/conf.go
@@ -51,9 +51,9 @@ func initConfig() {
 		bindConfig()
 		return
 	}
+
 	viper.WatchConfig()
 	viper.OnConfigChange(reInit)
-
 	bindConfig()
 }
 
@@ -62,12 +62,10 @@ func initConfig() {
 func initLogging() {
 
 	confObj.Mu.RLock()
-
 	if confObj.StdoutLogging {
 		log.SetOutput(os.Stdout)
 
 	} else {
-
 		logfile, err := os.OpenFile(confObj.LogFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600)
 		errLog("Could not open log file: ", err)
 
@@ -76,17 +74,13 @@ func initLogging() {
 		// to prevent race conditions when the config is
 		// reloaded.
 		go func(logfile *os.File) {
-
 			<-closeLog
-
 			log.Printf("Closing log file ...\n\n")
 			errLog("Could not close log file: ", logfile.Close())
-
 		}(logfile)
 
 		log.SetOutput(logfile)
 	}
-
 	confObj.Mu.RUnlock()
 }
 
@@ -140,42 +134,38 @@ func bindConfig() {
 
 	confObj.Port = viper.GetInt("ListenPort")
 	confObj.LogFile = viper.GetString("LogFile")
-
 	confObj.DBType = strings.ToLower(viper.GetString("DatabaseType"))
+	confObj.DBPath = viper.GetString("DatabasePath")
+	confObj.AssetsDir = viper.GetString("AssetsDirectory")
+	confObj.StdoutLogging = viper.GetBool("StdoutLogging")
+	confObj.CacheInterval = viper.GetDuration("StatusFetchInterval")
+	confObj.DBInterval = viper.GetDuration("DatabasePushInterval")
+
+	confObj.Instance.Vers = Vers
+	confObj.Instance.Name = viper.GetString("Instance.SiteName")
+	confObj.Instance.URL = viper.GetString("Instance.URL")
+	confObj.Instance.Owner = viper.GetString("Instance.OwnerName")
+	confObj.Instance.Mail = viper.GetString("Instance.Email")
+	confObj.Instance.Desc = viper.GetString("Instance.Description")
+
 	if *flagDBType != "" {
 		confObj.DBType = *flagDBType
 	}
-
-	confObj.DBPath = viper.GetString("DatabasePath")
 	if *flagDBPath != "" {
 		confObj.DBPath = *flagDBPath
 	}
-	log.Printf("Using %v database: %v\n", confObj.DBType, confObj.DBPath)
-
-	confObj.AssetsDir = viper.GetString("AssetsDirectory")
 	if *flagAssets != "" {
 		confObj.AssetsDir = *flagAssets
 	}
 
-	confObj.StdoutLogging = viper.GetBool("StdoutLogging")
 	if confObj.StdoutLogging {
-		log.Printf("Logging to stdout\n")
+		log.Printf("Logging to: stdout\n")
 	} else {
-		log.Printf("Logging to %v\n", confObj.LogFile)
+		log.Printf("Logging to: %v\n", confObj.LogFile)
 	}
-
-	confObj.CacheInterval = viper.GetDuration("StatusFetchInterval")
-	log.Printf("User status fetch interval: %v\n", confObj.CacheInterval)
-
-	confObj.DBInterval = viper.GetDuration("DatabasePushInterval")
+	log.Printf("Using %v database: %v\n", confObj.DBType, confObj.DBPath)
 	log.Printf("Database push interval: %v\n", confObj.DBInterval)
-
-	confObj.Instance.Vers = Vers
-	confObj.Instance.Name = viper.GetString("Instance.SiteName")
-	confObj.Instance.URL = viper.GetString("Instance.URL")
-	confObj.Instance.Owner = viper.GetString("Instance.OwnerName")
-	confObj.Instance.Mail = viper.GetString("Instance.Email")
-	confObj.Instance.Desc = viper.GetString("Instance.Description")
+	log.Printf("User status fetch interval: %v\n", confObj.CacheInterval)
 
 	confObj.Mu.Unlock()
 }
diff --git a/svc/init.go b/svc/init.go
index 537119c..d7419de 100644
--- a/svc/init.go
+++ b/svc/init.go
@@ -111,19 +111,18 @@ func watchForInterrupt() {
 
 	go func() {
 		for sigint := range c {
-
 			log.Printf("Caught %v. Cleaning up ...\n", sigint)
-			confObj.Mu.RLock()
-			log.Printf("Closing database connection to %v...\n", confObj.DBPath)
 
 			killTickers()
 			killDB()
 
+			confObj.Mu.RLock()
+			log.Printf("Closed database connection to %v\n", confObj.DBPath)
 			if !confObj.StdoutLogging {
 				closeLog <- true
 			}
-
 			confObj.Mu.RUnlock()
+
 			close(dbChan)
 			close(closeLog)