From 944e6bbde62c266aa3d50f0943a2716ac8d5df4b Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Thu, 11 Feb 2016 19:37:36 +0100 Subject: Chdir first (always) --- app_config.go | 13 ++++++------- domains_test.go | 2 +- helper_test.go | 2 +- main.go | 15 +++++++-------- server.go | 13 ++++++------- 5 files changed, 21 insertions(+), 24 deletions(-) diff --git a/app_config.go b/app_config.go index 6c96a59b..b7ba56fe 100644 --- a/app_config.go +++ b/app_config.go @@ -1,16 +1,15 @@ package main type appConfig struct { - Domain string - RootDir string + Domain string RootCertificate []byte RootKey []byte - ListenHTTP uintptr - ListenHTTPS uintptr - listenProxy uintptr + ListenHTTP uintptr + ListenHTTPS uintptr + listenProxy uintptr - HTTP2 bool - RedirectHTTP bool + HTTP2 bool + RedirectHTTP bool } diff --git a/domains_test.go b/domains_test.go index cfe93d53..8c3b1e5e 100644 --- a/domains_test.go +++ b/domains_test.go @@ -52,7 +52,7 @@ func TestWatchDomains(t *testing.T) { update := make(chan domains) go watchDomains("gitlab.io", func(domains domains) { update <- domains - }, time.Microsecond * 50) + }, time.Microsecond*50) defer os.Remove(updateFile) diff --git a/helper_test.go b/helper_test.go index 089e7403..5d564891 100644 --- a/helper_test.go +++ b/helper_test.go @@ -1,8 +1,8 @@ package main import ( - "os" "log" + "os" ) var chdirSet = false diff --git a/main.go b/main.go index d5c4b775..1d8d24cb 100644 --- a/main.go +++ b/main.go @@ -3,11 +3,11 @@ package main import ( "flag" "fmt" - "log" - "path/filepath" "io/ioutil" + "log" "net" "os" + "path/filepath" "strings" ) @@ -63,18 +63,17 @@ func main() { fmt.Printf("URL: https://gitlab.com/gitlab-org/gitlab-pages") flag.Parse() + err := os.Chdir(*pagesRoot) + if err != nil { + log.Fatalln(err) + } + var app theApp app.Domain = strings.ToLower(*pagesDomain) - app.RootDir = evalSymlinks(*pagesRoot) app.RedirectHTTP = *redirectHTTP app.HTTP2 = *useHTTP2 - err := os.Chdir(app.RootDir) - if err != nil { - log.Fatalln(err) - } - if *pagesRootCert != "" { app.RootCertificate = readFile(*pagesRootCert) } diff --git a/server.go b/server.go index 3f267b65..bee3e5f2 100644 --- a/server.go +++ b/server.go @@ -2,12 +2,12 @@ package main import ( "crypto/tls" + "fmt" "golang.org/x/net/http2" + "net" "net/http" -"net" - "time" "os" - "fmt" + "time" ) type tlsHandlerFunc func(*tls.ClientHelloInfo) (*tls.Certificate, error) @@ -45,12 +45,11 @@ func listenAndServe(fd uintptr, handler http.HandlerFunc, useHTTP2 bool, tlsConf if tlsConfig != nil { tlsListener := tls.NewListener(tcpKeepAliveListener{l.(*net.TCPListener)}, server.TLSConfig) return server.Serve(tlsListener) - } else { - return server.Serve(&tcpKeepAliveListener{l.(*net.TCPListener)}) } + return server.Serve(&tcpKeepAliveListener{l.(*net.TCPListener)}) } -func listenAndServeTLS(fd uintptr, cert, key []byte, handler http.HandlerFunc,tlsHandler tlsHandlerFunc, useHTTP2 bool) error { +func listenAndServeTLS(fd uintptr, cert, key []byte, handler http.HandlerFunc, tlsHandler tlsHandlerFunc, useHTTP2 bool) error { certificate, err := tls.X509KeyPair(cert, key) if err != nil { return err @@ -58,7 +57,7 @@ func listenAndServeTLS(fd uintptr, cert, key []byte, handler http.HandlerFunc,tl tlsConfig := &tls.Config{} tlsConfig.GetCertificate = tlsHandler - tlsConfig.NextProtos = []string { + tlsConfig.NextProtos = []string{ "http/1.1", } tlsConfig.Certificates = []tls.Certificate{ -- cgit v1.2.3