From 5e309a7b3a5d29323a6e08189ceb5c101fc38035 Mon Sep 17 00:00:00 2001
From: Simon Zolin <s.zolin@adguard.com>
Date: Tue, 9 Jul 2019 18:52:06 +0300
Subject: [PATCH] * move "httpServer" to "config"

---
 home/config.go          | 1 +
 home/control_install.go | 2 +-
 home/home.go            | 8 +++-----
 3 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/home/config.go b/home/config.go
index 0615613d..e3e1c0ab 100644
--- a/home/config.go
+++ b/home/config.go
@@ -70,6 +70,7 @@ type configuration struct {
 	versionCheckJSON     []byte
 	versionCheckLastTime time.Time
 
+	httpServer  *http.Server
 	httpsServer HTTPSServer
 
 	BindHost     string `yaml:"bind_host"`     // BindHost is the IP address of the HTTP server to bind to
diff --git a/home/control_install.go b/home/control_install.go
index f5758b99..30c48cca 100644
--- a/home/control_install.go
+++ b/home/control_install.go
@@ -264,7 +264,7 @@ func handleInstallConfigure(w http.ResponseWriter, r *http.Request) {
 	// until all requests are finished, and _we_ are inside a request right now, so it will block indefinitely
 	if restartHTTP {
 		go func() {
-			httpServer.Shutdown(context.TODO())
+			config.httpServer.Shutdown(context.TODO())
 		}()
 	}
 
diff --git a/home/home.go b/home/home.go
index 21061b92..81d4f0cc 100644
--- a/home/home.go
+++ b/home/home.go
@@ -25,8 +25,6 @@ import (
 	"github.com/gobuffalo/packr"
 )
 
-var httpServer *http.Server
-
 const (
 	// Used in config to indicate that syslog or eventlog (win) should be used for logger output
 	configSyslog = "syslog"
@@ -197,10 +195,10 @@ func run(args options) {
 
 		// we need to have new instance, because after Shutdown() the Server is not usable
 		address := net.JoinHostPort(config.BindHost, strconv.Itoa(config.BindPort))
-		httpServer = &http.Server{
+		config.httpServer = &http.Server{
 			Addr: address,
 		}
-		err := httpServer.ListenAndServe()
+		err := config.httpServer.ListenAndServe()
 		if err != http.ErrServerClosed {
 			cleanupAlways()
 			log.Fatal(err)
@@ -397,7 +395,7 @@ func stopHTTPServer() {
 	if config.httpsServer.server != nil {
 		config.httpsServer.server.Shutdown(context.TODO())
 	}
-	httpServer.Shutdown(context.TODO())
+	config.httpServer.Shutdown(context.TODO())
 }
 
 // This function is called before application exits