about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2020-05-06 01:11:39 -0400
committerBen Morrison <ben@gbmor.dev>2020-05-06 01:14:37 -0400
commitc759e1c8a0430bb5236cf1b086bdeacb42d707af (patch)
tree791c6fc67ebbe211ba178fa4f170818cba0415dd
parent860d648785e96ec8a23c16ad5c1ccbe16850cb1e (diff)
downloadapi-c759e1c8a0430bb5236cf1b086bdeacb42d707af.tar.gz
passing logfile close channel as param
-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)