about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--logging.go5
-rw-r--r--main.go7
2 files changed, 6 insertions, 6 deletions
diff --git a/logging.go b/logging.go
index 311aa8b..cd05006 100644
--- a/logging.go
+++ b/logging.go
@@ -7,9 +7,7 @@ import (
 	"os"
 )
 
-var logChan = make(chan struct{})
-
-func initLogging() {
+func initLogging(logChan <-chan struct{}) {
 	logfile, err := os.OpenFile("api.log", os.O_RDWR|os.O_APPEND|os.O_CREATE, 0644)
 	if err != nil {
 		log.SetOutput(os.Stderr)
@@ -20,6 +18,7 @@ func initLogging() {
 	go func(*os.File) {
 		<-logChan
 		log.Printf("Closing log file ...")
+
 		err := logfile.Close()
 		if err != nil {
 			log.SetOutput(os.Stderr)
diff --git a/main.go b/main.go
index 5662388..d8ca245 100644
--- a/main.go
+++ b/main.go
@@ -9,17 +9,18 @@ import (
 )
 
 func main() {
-	initLogging()
+	logChan := make(chan struct{})
+	initLogging(logChan)
 
 	sigC := make(chan os.Signal, 1)
 	signal.Notify(sigC, os.Interrupt)
-	go func() {
+	go func(chan<- struct{}) {
 		for range sigC {
 			log.Printf("^C Caught. Shutting down ...")
 			logChan <- struct{}{}
 			os.Exit(1)
 		}
-	}()
+	}(logChan)
 
 	mux := http.NewServeMux()
 	mux.HandleFunc("/", validateRequest)