From bf1f6f663a1cf3a5619c5ea2d7097b18a5f98836 Mon Sep 17 00:00:00 2001 From: David Tootill Date: Thu, 28 Apr 2016 10:53:02 +0000 Subject: [PATCH] Minor refactor as requested in PR comments --- examples/k8s.namespace.sh | 0 integration/access_log_test.go | 48 ++++++++++++++++------------------ middlewares/logger.go | 10 +++---- middlewares/saveBackend.go | 6 +---- 4 files changed, 27 insertions(+), 37 deletions(-) mode change 100644 => 100755 examples/k8s.namespace.sh diff --git a/examples/k8s.namespace.sh b/examples/k8s.namespace.sh old mode 100644 new mode 100755 diff --git a/integration/access_log_test.go b/integration/access_log_test.go index ffa2b0ae8..86db56668 100644 --- a/integration/access_log_test.go +++ b/integration/access_log_test.go @@ -37,9 +37,9 @@ func (s *AccessLogSuite) TestAccessLog(c *check.C) { time.Sleep(500 * time.Millisecond) // Verify Traefik started OK - if traefikLog, err := ioutil.ReadFile("traefik.log"); err != nil { - c.Assert(err.Error(), checker.Equals, "") - } else if len(traefikLog) > 0 { + traefikLog, err := ioutil.ReadFile("traefik.log") + c.Assert(err, checker.IsNil) + if len(traefikLog) > 0 { fmt.Printf("%s\n", string(traefikLog)) c.Assert(len(traefikLog), checker.Equals, 0) } @@ -61,33 +61,29 @@ func (s *AccessLogSuite) TestAccessLog(c *check.C) { c.Assert(err, checker.IsNil) // Verify access.log output as expected - if accessLog, err := ioutil.ReadFile("access.log"); err != nil { - c.Assert(err.Error(), checker.Equals, "") - } else { - lines := strings.Split(string(accessLog), "\n") - count := 0 - for i, line := range lines { - if len(line) > 0 { - count++ - if tokens, err := shellwords.Parse(line); err != nil { - c.Assert(err.Error(), checker.Equals, "") - } else { - c.Assert(len(tokens), checker.Equals, 13) - c.Assert(tokens[6], checker.Equals, "200") - c.Assert(tokens[9], checker.Equals, fmt.Sprintf("%d", i+1)) - c.Assert(strings.HasPrefix(tokens[10], "frontend"), checker.True) - c.Assert(strings.HasPrefix(tokens[11], "http://127.0.0.1:808"), checker.True) - c.Assert(regexp.MustCompile("^\\d+\\.\\d+.*s$").MatchString(tokens[12]), checker.True) - } - } + accessLog, err := ioutil.ReadFile("access.log") + c.Assert(err, checker.IsNil) + lines := strings.Split(string(accessLog), "\n") + count := 0 + for i, line := range lines { + if len(line) > 0 { + count++ + tokens, err := shellwords.Parse(line) + c.Assert(err, checker.IsNil) + c.Assert(len(tokens), checker.Equals, 13) + c.Assert(tokens[6], checker.Equals, "200") + c.Assert(tokens[9], checker.Equals, fmt.Sprintf("%d", i+1)) + c.Assert(strings.HasPrefix(tokens[10], "frontend"), checker.True) + c.Assert(strings.HasPrefix(tokens[11], "http://127.0.0.1:808"), checker.True) + c.Assert(regexp.MustCompile("^\\d+\\.\\d+.*s$").MatchString(tokens[12]), checker.True) } - c.Assert(count, checker.Equals, 3) } + c.Assert(count, checker.Equals, 3) // Verify no other Traefik problems - if traefikLog, err := ioutil.ReadFile("traefik.log"); err != nil { - c.Assert(err.Error(), checker.Equals, "") - } else if len(traefikLog) > 0 { + traefikLog, err = ioutil.ReadFile("traefik.log") + c.Assert(err, checker.IsNil) + if len(traefikLog) > 0 { fmt.Printf("%s\n", string(traefikLog)) c.Assert(len(traefikLog), checker.Equals, 0) } diff --git a/middlewares/logger.go b/middlewares/logger.go index ea2d228f7..6efc5ca30 100644 --- a/middlewares/logger.go +++ b/middlewares/logger.go @@ -1,10 +1,5 @@ package middlewares -/* -Middleware Logger writes each request and its response to the access log. -It gets some information from the logInfoResponseWriter set up by previous middleware. -*/ - import ( "fmt" log "github.com/Sirupsen/logrus" @@ -23,7 +18,10 @@ const ( loggerReqidHeader = "X-Traefik-Reqid" ) -// Logger holds the File defining the access log +/* +Middleware Logger writes each request and its response to the access log. +It gets some information from the logInfoResponseWriter set up by previous middleware. +*/ type Logger struct { file *os.File } diff --git a/middlewares/saveBackend.go b/middlewares/saveBackend.go index 459c8d184..0a7b28e32 100644 --- a/middlewares/saveBackend.go +++ b/middlewares/saveBackend.go @@ -1,14 +1,10 @@ package middlewares -/* -Middleware saveBackend sends the backend name to the logger. -*/ - import ( "net/http" ) -// SaveBackend holds the next handler +// Middleware saveBackend sends the backend name to the logger. type SaveBackend struct { next http.Handler }