From cae9f7de9c7915bfd02cc8606df9029986c97071 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Sun, 14 Feb 2016 00:10:57 -0700 Subject: [PATCH] gofmt -s; fix misspellings and lint; Go 1.5.3 in Travis CI --- .travis.yml | 2 +- caddy/https/https.go | 2 +- caddy/https/https_test.go | 34 +++++++++++++-------------- caddy/parse/parsing_test.go | 20 ++++++++-------- caddy/setup/browse_test.go | 2 +- caddy/setup/redir_test.go | 20 ++++++++-------- caddy/setup/rewrite_test.go | 2 +- caddy/setup/startupshutdown_test.go | 2 +- middleware/context_test.go | 8 +++---- middleware/fastcgi/fastcgi.go | 2 +- middleware/fastcgi/fastcgi_test.go | 8 +++---- middleware/fastcgi/fcgiclient_test.go | 8 +++---- middleware/fileserver_test.go | 4 ++-- middleware/middleware.go | 3 ++- middleware/proxy/proxy_test.go | 4 ++-- server/server.go | 2 +- 16 files changed, 61 insertions(+), 62 deletions(-) diff --git a/.travis.yml b/.travis.yml index 19ba6dba..92bbffe5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: go go: - 1.4.3 - - 1.5.2 + - 1.5.3 - tip install: diff --git a/caddy/https/https.go b/caddy/https/https.go index cfff2868..f6cdcd46 100644 --- a/caddy/https/https.go +++ b/caddy/https/https.go @@ -336,7 +336,7 @@ func redirPlaintextHost(cfg server.Config) server.Config { BindHost: cfg.BindHost, Port: "80", Middleware: map[string][]middleware.Middleware{ - "/": []middleware.Middleware{redirMidware}, + "/": {redirMidware}, }, } } diff --git a/caddy/https/https_test.go b/caddy/https/https_test.go index d724635b..199c6266 100644 --- a/caddy/https/https_test.go +++ b/caddy/https/https_test.go @@ -209,9 +209,9 @@ func TestExistingCertAndKey(t *testing.T) { func TestHostHasOtherPort(t *testing.T) { configs := []server.Config{ - server.Config{Host: "example.com", Port: "80"}, - server.Config{Host: "sub1.example.com", Port: "80"}, - server.Config{Host: "sub1.example.com", Port: "443"}, + {Host: "example.com", Port: "80"}, + {Host: "sub1.example.com", Port: "80"}, + {Host: "sub1.example.com", Port: "443"}, } if hostHasOtherPort(configs, 0, "80") { @@ -228,18 +228,18 @@ func TestHostHasOtherPort(t *testing.T) { func TestMakePlaintextRedirects(t *testing.T) { configs := []server.Config{ // Happy path = standard redirect from 80 to 443 - server.Config{Host: "example.com", TLS: server.TLSConfig{Managed: true}}, + {Host: "example.com", TLS: server.TLSConfig{Managed: true}}, // Host on port 80 already defined; don't change it (no redirect) - server.Config{Host: "sub1.example.com", Port: "80", Scheme: "http"}, - server.Config{Host: "sub1.example.com", TLS: server.TLSConfig{Managed: true}}, + {Host: "sub1.example.com", Port: "80", Scheme: "http"}, + {Host: "sub1.example.com", TLS: server.TLSConfig{Managed: true}}, // Redirect from port 80 to port 5000 in this case - server.Config{Host: "sub2.example.com", Port: "5000", TLS: server.TLSConfig{Managed: true}}, + {Host: "sub2.example.com", Port: "5000", TLS: server.TLSConfig{Managed: true}}, // Can redirect from 80 to either 443 or 5001, but choose 443 - server.Config{Host: "sub3.example.com", Port: "443", TLS: server.TLSConfig{Managed: true}}, - server.Config{Host: "sub3.example.com", Port: "5001", Scheme: "https", TLS: server.TLSConfig{Managed: true}}, + {Host: "sub3.example.com", Port: "443", TLS: server.TLSConfig{Managed: true}}, + {Host: "sub3.example.com", Port: "5001", Scheme: "https", TLS: server.TLSConfig{Managed: true}}, } result := MakePlaintextRedirects(configs) @@ -253,8 +253,8 @@ func TestMakePlaintextRedirects(t *testing.T) { func TestEnableTLS(t *testing.T) { configs := []server.Config{ - server.Config{Host: "example.com", TLS: server.TLSConfig{Managed: true}}, - server.Config{}, // not managed - no changes! + {Host: "example.com", TLS: server.TLSConfig{Managed: true}}, + {}, // not managed - no changes! } EnableTLS(configs, false) @@ -273,12 +273,12 @@ func TestGroupConfigsByEmail(t *testing.T) { } configs := []server.Config{ - server.Config{Host: "example.com", TLS: server.TLSConfig{LetsEncryptEmail: "", Managed: true}}, - server.Config{Host: "sub1.example.com", TLS: server.TLSConfig{LetsEncryptEmail: "foo@bar", Managed: true}}, - server.Config{Host: "sub2.example.com", TLS: server.TLSConfig{LetsEncryptEmail: "", Managed: true}}, - server.Config{Host: "sub3.example.com", TLS: server.TLSConfig{LetsEncryptEmail: "foo@bar", Managed: true}}, - server.Config{Host: "sub4.example.com", TLS: server.TLSConfig{LetsEncryptEmail: "", Managed: true}}, - server.Config{Host: "sub5.example.com", TLS: server.TLSConfig{LetsEncryptEmail: ""}}, // not managed + {Host: "example.com", TLS: server.TLSConfig{LetsEncryptEmail: "", Managed: true}}, + {Host: "sub1.example.com", TLS: server.TLSConfig{LetsEncryptEmail: "foo@bar", Managed: true}}, + {Host: "sub2.example.com", TLS: server.TLSConfig{LetsEncryptEmail: "", Managed: true}}, + {Host: "sub3.example.com", TLS: server.TLSConfig{LetsEncryptEmail: "foo@bar", Managed: true}}, + {Host: "sub4.example.com", TLS: server.TLSConfig{LetsEncryptEmail: "", Managed: true}}, + {Host: "sub5.example.com", TLS: server.TLSConfig{LetsEncryptEmail: ""}}, // not managed } DefaultEmail = "test@example.com" diff --git a/caddy/parse/parsing_test.go b/caddy/parse/parsing_test.go index 462cd40f..493c0fff 100644 --- a/caddy/parse/parsing_test.go +++ b/caddy/parse/parsing_test.go @@ -311,19 +311,19 @@ func TestParseAll(t *testing.T) { }}, {`localhost:1234`, false, [][]address{ - []address{{"localhost:1234", "", "localhost", "1234"}}, + {{"localhost:1234", "", "localhost", "1234"}}, }}, {`localhost:1234 { } localhost:2015 { }`, false, [][]address{ - []address{{"localhost:1234", "", "localhost", "1234"}}, - []address{{"localhost:2015", "", "localhost", "2015"}}, + {{"localhost:1234", "", "localhost", "1234"}}, + {{"localhost:2015", "", "localhost", "2015"}}, }}, {`localhost:1234, http://host2`, false, [][]address{ - []address{{"localhost:1234", "", "localhost", "1234"}, {"http://host2", "http", "host2", "80"}}, + {{"localhost:1234", "", "localhost", "1234"}, {"http://host2", "http", "host2", "80"}}, }}, {`localhost:1234, http://host2,`, true, [][]address{}}, @@ -332,15 +332,15 @@ func TestParseAll(t *testing.T) { } https://host3.com, https://host4.com { }`, false, [][]address{ - []address{{"http://host1.com", "http", "host1.com", "80"}, {"http://host2.com", "http", "host2.com", "80"}}, - []address{{"https://host3.com", "https", "host3.com", "443"}, {"https://host4.com", "https", "host4.com", "443"}}, + {{"http://host1.com", "http", "host1.com", "80"}, {"http://host2.com", "http", "host2.com", "80"}}, + {{"https://host3.com", "https", "host3.com", "443"}, {"https://host4.com", "https", "host4.com", "443"}}, }}, {`import import_glob*.txt`, false, [][]address{ - []address{{"glob0.host0", "", "glob0.host0", ""}}, - []address{{"glob0.host1", "", "glob0.host1", ""}}, - []address{{"glob1.host0", "", "glob1.host0", ""}}, - []address{{"glob2.host0", "", "glob2.host0", ""}}, + {{"glob0.host0", "", "glob0.host0", ""}}, + {{"glob0.host1", "", "glob0.host1", ""}}, + {{"glob1.host0", "", "glob1.host0", ""}}, + {{"glob2.host0", "", "glob2.host0", ""}}, }}, } { p := testParser(test.input) diff --git a/caddy/setup/browse_test.go b/caddy/setup/browse_test.go index 3714a51d..443e008b 100644 --- a/caddy/setup/browse_test.go +++ b/caddy/setup/browse_test.go @@ -41,7 +41,7 @@ func TestBrowse(t *testing.T) { // test case #2 tests detectaction of custom template {"browse . " + tempTemplatePath, []string{"."}, false}, - // test case #3 tests detection of non-existant template + // test case #3 tests detection of non-existent template {"browse . " + nonExistantDirPath, nil, true}, // test case #4 tests detection of duplicate pathscopes diff --git a/caddy/setup/redir_test.go b/caddy/setup/redir_test.go index 773666f8..0285784f 100644 --- a/caddy/setup/redir_test.go +++ b/caddy/setup/redir_test.go @@ -14,34 +14,34 @@ func TestRedir(t *testing.T) { expectedRules []redirect.Rule }{ // test case #0 tests the recognition of a valid HTTP status code defined outside of block statement - {"redir 300 {\n/ /foo\n}", false, []redirect.Rule{redirect.Rule{FromPath: "/", To: "/foo", Code: 300}}}, + {"redir 300 {\n/ /foo\n}", false, []redirect.Rule{{FromPath: "/", To: "/foo", Code: 300}}}, // test case #1 tests the recognition of an invalid HTTP status code defined outside of block statement - {"redir 9000 {\n/ /foo\n}", true, []redirect.Rule{redirect.Rule{}}}, + {"redir 9000 {\n/ /foo\n}", true, []redirect.Rule{{}}}, // test case #2 tests the detection of a valid HTTP status code outside of a block statement being overriden by an invalid HTTP status code inside statement of a block statement - {"redir 300 {\n/ /foo 9000\n}", true, []redirect.Rule{redirect.Rule{}}}, + {"redir 300 {\n/ /foo 9000\n}", true, []redirect.Rule{{}}}, // test case #3 tests the detection of an invalid HTTP status code outside of a block statement being overriden by a valid HTTP status code inside statement of a block statement - {"redir 9000 {\n/ /foo 300\n}", true, []redirect.Rule{redirect.Rule{}}}, + {"redir 9000 {\n/ /foo 300\n}", true, []redirect.Rule{{}}}, // test case #4 tests the recognition of a TO redirection in a block statement.The HTTP status code is set to the default of 301 - MovedPermanently - {"redir 302 {\n/foo\n}", false, []redirect.Rule{redirect.Rule{FromPath: "/", To: "/foo", Code: 302}}}, + {"redir 302 {\n/foo\n}", false, []redirect.Rule{{FromPath: "/", To: "/foo", Code: 302}}}, // test case #5 tests the recognition of a TO and From redirection in a block statement - {"redir {\n/bar /foo 303\n}", false, []redirect.Rule{redirect.Rule{FromPath: "/bar", To: "/foo", Code: 303}}}, + {"redir {\n/bar /foo 303\n}", false, []redirect.Rule{{FromPath: "/bar", To: "/foo", Code: 303}}}, // test case #6 tests the recognition of a TO redirection in a non-block statement. The HTTP status code is set to the default of 301 - MovedPermanently - {"redir /foo", false, []redirect.Rule{redirect.Rule{FromPath: "/", To: "/foo", Code: 301}}}, + {"redir /foo", false, []redirect.Rule{{FromPath: "/", To: "/foo", Code: 301}}}, // test case #7 tests the recognition of a TO and From redirection in a non-block statement - {"redir /bar /foo 303", false, []redirect.Rule{redirect.Rule{FromPath: "/bar", To: "/foo", Code: 303}}}, + {"redir /bar /foo 303", false, []redirect.Rule{{FromPath: "/bar", To: "/foo", Code: 303}}}, // test case #8 tests the recognition of multiple redirections - {"redir {\n / /foo 304 \n} \n redir {\n /bar /foobar 305 \n}", false, []redirect.Rule{redirect.Rule{FromPath: "/", To: "/foo", Code: 304}, redirect.Rule{FromPath: "/bar", To: "/foobar", Code: 305}}}, + {"redir {\n / /foo 304 \n} \n redir {\n /bar /foobar 305 \n}", false, []redirect.Rule{{FromPath: "/", To: "/foo", Code: 304}, {FromPath: "/bar", To: "/foobar", Code: 305}}}, // test case #9 tests the detection of duplicate redirections - {"redir {\n /bar /foo 304 \n} redir {\n /bar /foo 304 \n}", true, []redirect.Rule{redirect.Rule{}}}, + {"redir {\n /bar /foo 304 \n} redir {\n /bar /foo 304 \n}", true, []redirect.Rule{{}}}, } { recievedFunc, err := Redir(NewTestController(test.input)) if err != nil && !test.shouldErr { diff --git a/caddy/setup/rewrite_test.go b/caddy/setup/rewrite_test.go index 224ab643..29bfe997 100644 --- a/caddy/setup/rewrite_test.go +++ b/caddy/setup/rewrite_test.go @@ -135,7 +135,7 @@ func TestRewriteParse(t *testing.T) { to /to if {path} is a }`, false, []rewrite.Rule{ - &rewrite.ComplexRule{Base: "/", To: "/to", Ifs: []rewrite.If{rewrite.If{A: "{path}", Operator: "is", B: "a"}}}, + &rewrite.ComplexRule{Base: "/", To: "/to", Ifs: []rewrite.If{{A: "{path}", Operator: "is", B: "a"}}}, }}, {`rewrite { status 400 diff --git a/caddy/setup/startupshutdown_test.go b/caddy/setup/startupshutdown_test.go index 16fa973c..871a6421 100644 --- a/caddy/setup/startupshutdown_test.go +++ b/caddy/setup/startupshutdown_test.go @@ -37,7 +37,7 @@ func TestStartup(t *testing.T) { // test case #1 tests proper functionality of non-blocking commands {"startup mkdir " + osSenitiveTestDir + " &", false, true}, - // test case #2 tests handling of non-existant commands + // test case #2 tests handling of non-existent commands {"startup " + strconv.Itoa(int(time.Now().UnixNano())), true, true}, } diff --git a/middleware/context_test.go b/middleware/context_test.go index 5fb883c6..5c6473e9 100644 --- a/middleware/context_test.go +++ b/middleware/context_test.go @@ -105,13 +105,13 @@ func TestMarkdown(t *testing.T) { }() tests := []struct { - fileContent string - expectedContent string + fileContent string + expectedContent string }{ // Test 0 - test parsing of markdown { - fileContent: "* str1\n* str2\n", - expectedContent: "\n", + fileContent: "* str1\n* str2\n", + expectedContent: "\n", }, } diff --git a/middleware/fastcgi/fastcgi.go b/middleware/fastcgi/fastcgi.go index 153cae7f..bddb0470 100755 --- a/middleware/fastcgi/fastcgi.go +++ b/middleware/fastcgi/fastcgi.go @@ -138,7 +138,7 @@ func (r Rule) parseAddress() (string, string) { if strings.HasPrefix(r.Address, "tcp://") { return "tcp", r.Address[len("tcp://"):] } - // check if address has fastcgi scheme explicity set + // check if address has fastcgi scheme explicitly set if strings.HasPrefix(r.Address, "fastcgi://") { return "tcp", r.Address[len("fastcgi://"):] } diff --git a/middleware/fastcgi/fastcgi_test.go b/middleware/fastcgi/fastcgi_test.go index 1fc7446d..c33f47af 100644 --- a/middleware/fastcgi/fastcgi_test.go +++ b/middleware/fastcgi/fastcgi_test.go @@ -35,20 +35,20 @@ func TestRuleParseAddress(t *testing.T) { func TestBuildEnv(t *testing.T) { buildEnvSingle := func(r *http.Request, rule Rule, fpath string, envExpected map[string]string, t *testing.T) { - + h := Handler{} - + env, err := h.buildEnv(r, rule, fpath) if err != nil { t.Error("Unexpected error:", err.Error()) } - + for k, v := range envExpected { if env[k] != v { t.Errorf("Unexpected %v. Got %v, expected %v", k, env[k], v) } } - + } rule := Rule{} diff --git a/middleware/fastcgi/fcgiclient_test.go b/middleware/fastcgi/fcgiclient_test.go index 6ed37bb4..0eeebb4b 100644 --- a/middleware/fastcgi/fcgiclient_test.go +++ b/middleware/fastcgi/fcgiclient_test.go @@ -39,9 +39,7 @@ const ( ipPort = "127.0.0.1:59000" ) -var ( - t_ *testing.T -) +var globalt *testing.T type FastCGIServer struct{} @@ -158,7 +156,7 @@ func sendFcgi(reqType int, fcgiParams map[string]string, data []byte, posts map[ time.Sleep(1 * time.Second) if bytes.Index(content, []byte("FAILED")) >= 0 { - t_.Error("Server return failed message") + globalt.Error("Server return failed message") } return @@ -193,7 +191,7 @@ func generateRandFile(size int) (p string, m string) { func DisabledTest(t *testing.T) { // TODO: test chunked reader - t_ = t + globalt = t rand.Seed(time.Now().UTC().UnixNano()) diff --git a/middleware/fileserver_test.go b/middleware/fileserver_test.go index 0ce454bb..0f5b1fac 100644 --- a/middleware/fileserver_test.go +++ b/middleware/fileserver_test.go @@ -45,7 +45,7 @@ func TestServeHTTP(t *testing.T) { expectedStatus int expectedBodyContent string }{ - // Test 0 - access withoutt any path + // Test 0 - access without any path { url: "https://foo", expectedStatus: http.StatusNotFound, @@ -78,7 +78,7 @@ func TestServeHTTP(t *testing.T) { url: "https://foo/dir/", expectedStatus: http.StatusNotFound, }, - // Test 6 - access folder withtout trailing slash + // Test 6 - access folder without trailing slash { url: "https://foo/dir", expectedStatus: http.StatusMovedPermanently, diff --git a/middleware/middleware.go b/middleware/middleware.go index b88b2447..c7036f3c 100644 --- a/middleware/middleware.go +++ b/middleware/middleware.go @@ -102,7 +102,8 @@ func SetLastModifiedHeader(w http.ResponseWriter, modTime time.Time) { w.Header().Set("Last-Modified", modTime.UTC().Format(http.TimeFormat)) } -// currentTime returns time.Now() everytime it's called. It's used for mocking in tests. +// currentTime, as it is defined here, returns time.Now(). +// It's defined as a variable for mocking time in tests. var currentTime = func() time.Time { return time.Now() } diff --git a/middleware/proxy/proxy_test.go b/middleware/proxy/proxy_test.go index 68b13567..8066874d 100644 --- a/middleware/proxy/proxy_test.go +++ b/middleware/proxy/proxy_test.go @@ -12,11 +12,11 @@ import ( "net/http/httptest" "net/url" "os" + "path/filepath" + "runtime" "strings" "testing" - "runtime" "time" - "path/filepath" "golang.org/x/net/websocket" ) diff --git a/server/server.go b/server/server.go index 3b38e483..c921566c 100644 --- a/server/server.go +++ b/server/server.go @@ -336,7 +336,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { if err != nil { remoteHost = r.RemoteAddr } - + w.WriteHeader(http.StatusNotFound) fmt.Fprintf(w, "No such host at %s", s.Server.Addr) log.Printf("[INFO] %s - No such host at %s (requested by %s)", host, s.Server.Addr, remoteHost)