From 3d1cac313c0a47b82969ebbdca0bec1e0afae10f Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Thu, 10 Sep 2015 19:52:23 -0700 Subject: [PATCH 1/5] Use %v instead of %p to calm vet Signed-off-by: Alexander Morozov --- config/setup/controllertest.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/setup/controllertest.go b/config/setup/controllertest.go index dcb2ca82..25592940 100644 --- a/config/setup/controllertest.go +++ b/config/setup/controllertest.go @@ -28,5 +28,5 @@ var EmptyNext = middleware.HandlerFunc(func(w http.ResponseWriter, r *http.Reque // SameNext does a pointer comparison between next1 and next2. func SameNext(next1, next2 middleware.Handler) bool { - return fmt.Sprintf("%p", next1) == fmt.Sprintf("%p", next2) + return fmt.Sprintf("%v", next1) == fmt.Sprintf("%v", next2) } From 80db177f5a20d95e179e7e46b834dc6d5c974238 Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Thu, 10 Sep 2015 19:57:23 -0700 Subject: [PATCH 2/5] Fix vet warnings about unkeyed fields Signed-off-by: Alexander Morozov --- config/setup/gzip.go | 4 ++-- config/setup/rewrite_test.go | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/config/setup/gzip.go b/config/setup/gzip.go index e78d374a..a81c5f17 100644 --- a/config/setup/gzip.go +++ b/config/setup/gzip.go @@ -27,8 +27,8 @@ func gzipParse(c *Controller) ([]gzip.Config, error) { for c.Next() { config := gzip.Config{} - pathFilter := gzip.PathFilter{make(gzip.Set)} - extFilter := gzip.ExtFilter{make(gzip.Set)} + pathFilter := gzip.PathFilter{IgnoredPaths: make(gzip.Set)} + extFilter := gzip.ExtFilter{Exts: make(gzip.Set)} // No extra args expected if len(c.RemainingArgs()) > 0 { diff --git a/config/setup/rewrite_test.go b/config/setup/rewrite_test.go index 6ce8d97e..f5426678 100644 --- a/config/setup/rewrite_test.go +++ b/config/setup/rewrite_test.go @@ -42,17 +42,17 @@ func TestRewriteParse(t *testing.T) { expected []rewrite.Rule }{ {`rewrite /from /to`, false, []rewrite.Rule{ - rewrite.SimpleRule{"/from", "/to"}, + rewrite.SimpleRule{From: "/from", To: "/to"}, }}, {`rewrite /from /to rewrite a b`, false, []rewrite.Rule{ - rewrite.SimpleRule{"/from", "/to"}, - rewrite.SimpleRule{"a", "b"}, + rewrite.SimpleRule{From: "/from", To: "/to"}, + rewrite.SimpleRule{From: "a", To: "b"}, }}, {`rewrite a`, true, []rewrite.Rule{}}, {`rewrite`, true, []rewrite.Rule{}}, {`rewrite a b c`, true, []rewrite.Rule{ - rewrite.SimpleRule{"a", "b"}, + rewrite.SimpleRule{From: "a", To: "b"}, }}, } @@ -98,14 +98,14 @@ func TestRewriteParse(t *testing.T) { r .* to /to }`, false, []rewrite.Rule{ - &rewrite.RegexpRule{"/", "/to", nil, regexp.MustCompile(".*")}, + &rewrite.RegexpRule{Base: "/", To: "/to", Regexp: regexp.MustCompile(".*")}, }}, {`rewrite { regexp .* to /to ext / html txt }`, false, []rewrite.Rule{ - &rewrite.RegexpRule{"/", "/to", []string{"/", "html", "txt"}, regexp.MustCompile(".*")}, + &rewrite.RegexpRule{Base: "/", To: "/to", Exts: []string{"/", "html", "txt"}, Regexp: regexp.MustCompile(".*")}, }}, {`rewrite /path { r rr @@ -116,8 +116,8 @@ func TestRewriteParse(t *testing.T) { to /to } `, false, []rewrite.Rule{ - &rewrite.RegexpRule{"/path", "/dest", nil, regexp.MustCompile("rr")}, - &rewrite.RegexpRule{"/", "/to", nil, regexp.MustCompile("[a-z]+")}, + &rewrite.RegexpRule{Base: "/path", To: "/dest", Regexp: regexp.MustCompile("rr")}, + &rewrite.RegexpRule{Base: "/", To: "/to", Regexp: regexp.MustCompile("[a-z]+")}, }}, {`rewrite { to /to From 1236e492a969115d2b40bd51502cff1953e012ce Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Thu, 10 Sep 2015 19:59:19 -0700 Subject: [PATCH 3/5] Fix format verbs for funcs Signed-off-by: Alexander Morozov --- config/setup/basicauth_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/setup/basicauth_test.go b/config/setup/basicauth_test.go index c5a80530..7588f0f0 100644 --- a/config/setup/basicauth_test.go +++ b/config/setup/basicauth_test.go @@ -117,7 +117,7 @@ md5:$apr1$l42y8rex$pOA2VJ0x/0TwaFeAF9nX61` pwd = fmt.Sprintf("%s%d", pwd, j+1) } if !actualRule.Password(pwd) || actualRule.Password(test.password+"!") { - t.Errorf("Test %d, rule %d: Expected password '%s', got '%s'", + t.Errorf("Test %d, rule %d: Expected password '%v', got '%v'", i, j, test.password, actualRule.Password) } From 740a6a7ad5dfd6de46d2c33aa3f81722c1d5e09b Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Thu, 10 Sep 2015 20:52:49 -0700 Subject: [PATCH 4/5] Use func from stdlib to clone *tls.Config for calming vet Signed-off-by: Alexander Morozov --- server/server.go | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/server/server.go b/server/server.go index 89c81a4f..4f29c646 100644 --- a/server/server.go +++ b/server/server.go @@ -113,6 +113,34 @@ func (s *Server) Serve() error { return server.ListenAndServe() } +// copy from net/http/transport.go +func cloneTLSConfig(cfg *tls.Config) *tls.Config { + if cfg == nil { + return &tls.Config{} + } + return &tls.Config{ + Rand: cfg.Rand, + Time: cfg.Time, + Certificates: cfg.Certificates, + NameToCertificate: cfg.NameToCertificate, + GetCertificate: cfg.GetCertificate, + RootCAs: cfg.RootCAs, + NextProtos: cfg.NextProtos, + ServerName: cfg.ServerName, + ClientAuth: cfg.ClientAuth, + ClientCAs: cfg.ClientCAs, + InsecureSkipVerify: cfg.InsecureSkipVerify, + CipherSuites: cfg.CipherSuites, + PreferServerCipherSuites: cfg.PreferServerCipherSuites, + SessionTicketsDisabled: cfg.SessionTicketsDisabled, + SessionTicketKey: cfg.SessionTicketKey, + ClientSessionCache: cfg.ClientSessionCache, + MinVersion: cfg.MinVersion, + MaxVersion: cfg.MaxVersion, + CurvePreferences: cfg.CurvePreferences, + } +} + // ListenAndServeTLSWithSNI serves TLS with Server Name Indication (SNI) support, which allows // multiple sites (different hostnames) to be served from the same address. This method is // adapted directly from the std lib's net/http ListenAndServeTLS function, which was @@ -123,10 +151,7 @@ func ListenAndServeTLSWithSNI(srv *http.Server, tlsConfigs []TLSConfig) error { addr = ":https" } - config := new(tls.Config) - if srv.TLSConfig != nil { - *config = *srv.TLSConfig - } + config := cloneTLSConfig(srv.TLSConfig) if config.NextProtos == nil { config.NextProtos = []string{"http/1.1"} } From f2e680430adb88eb9576cdccda5a5d5b013d4315 Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Thu, 10 Sep 2015 20:05:52 -0700 Subject: [PATCH 5/5] Add vet check to CI Signed-off-by: Alexander Morozov --- .travis.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 47e2d4f5..7b71caef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,4 +5,10 @@ go: - 1.5 - tip -script: go test ./... +install: + - go get -d ./... + - go get golang.org/x/tools/cmd/vet + +script: + - go vet ./... + - go test ./...