From baf326391314de03030af21ee16db859a4d796f9 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Tue, 3 Apr 2012 09:10:24 -0400 Subject: [PATCH] Config now only need be declared once in package server --- main.go | 2 +- server/paths.go | 7 ------- server/server.go | 10 ++++++---- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/main.go b/main.go index 5fe6ef4..8109fd5 100644 --- a/main.go +++ b/main.go @@ -54,5 +54,5 @@ func main() { fmt.Printf("Starting Armadillo on port %d with root:\n %v\n", configuration.Port, configuration.JailRoot) server.SetConfig(configuration) - server.RunBackEnd(configuration) + server.RunBackEnd() } diff --git a/server/paths.go b/server/paths.go index ee46174..ae084fb 100644 --- a/server/paths.go +++ b/server/paths.go @@ -10,19 +10,12 @@ package server import ( - "../config" "errors" "os" "path" "strings" ) -var gConfig *config.Configuration - -func SetConfig(aConfig *config.Configuration) { - gConfig = aConfig -} - func canonicalizePath(raw_path string) string { raw_path = path.Join(gConfig.JailRoot, raw_path) return path.Clean(raw_path) diff --git a/server/server.go b/server/server.go index d508290..db101ab 100644 --- a/server/server.go +++ b/server/server.go @@ -25,7 +25,11 @@ import ( var dir, file = path.Split(path.Clean(os.Getenv("_"))) var kFrontEndFiles string = path.Join(dir, "fe") -var gConfig *config.Configuration = nil +var gConfig *config.Configuration + +func SetConfig(aConfig *config.Configuration) { + gConfig = aConfig +} func indexHandler(response http.ResponseWriter, request *http.Request) { fd, err := os.Open(path.Join(kFrontEndFiles, "index.html")) @@ -197,7 +201,7 @@ func okResponse(response http.ResponseWriter, data interface{}) { } } -func RunBackEnd(config *config.Configuration) { +func RunBackEnd() { mux := http.NewServeMux() mux.HandleFunc("/", indexHandler) mux.Handle("/fe/", http.StripPrefix("/fe/", http.FileServer(http.Dir(kFrontEndFiles)))) @@ -205,8 +209,6 @@ func RunBackEnd(config *config.Configuration) { mux.HandleFunc("/download", downloadHandler) mux.HandleFunc("/proxy", proxyHandler) - gConfig = config - error := http.ListenAndServe(fmt.Sprintf(":%d", config.Port), mux) fmt.Printf("error %v", error) } -- 2.22.5