From 615c62d73606bd44126b6158d951bfb0c1b492e7 Mon Sep 17 00:00:00 2001 From: Manu Mtz-Almeida Date: Mon, 23 Mar 2015 04:41:29 +0100 Subject: [PATCH] Some cosmetic changes --- gin.go | 15 +++++---------- gin_test.go | 2 +- recovery_test.go | 4 ++-- utils.go | 9 ++++----- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/gin.go b/gin.go index c23577df..fe3d5dc3 100644 --- a/gin.go +++ b/gin.go @@ -5,12 +5,13 @@ package gin import ( - "github.com/gin-gonic/gin/render" - "github.com/julienschmidt/httprouter" "html/template" "math" "net/http" "sync" + + "github.com/gin-gonic/gin/render" + "github.com/julienschmidt/httprouter" ) const ( @@ -158,16 +159,10 @@ func (engine *Engine) ServeHTTP(writer http.ResponseWriter, request *http.Reques func (engine *Engine) Run(addr string) error { debugPrint("Listening and serving HTTP on %s\n", addr) - if err := http.ListenAndServe(addr, engine); err != nil { - return err - } - return nil + return http.ListenAndServe(addr, engine) } func (engine *Engine) RunTLS(addr string, cert string, key string) error { debugPrint("Listening and serving HTTPS on %s\n", addr) - if err := http.ListenAndServeTLS(addr, cert, key, engine); err != nil { - return err - } - return nil + return http.ListenAndServeTLS(addr, cert, key, engine) } diff --git a/gin_test.go b/gin_test.go index ba74c159..07581539 100644 --- a/gin_test.go +++ b/gin_test.go @@ -192,7 +192,7 @@ func TestHandleHeadToDir(t *testing.T) { // TEST bodyAsString := w.Body.String() if w.Code != 200 { - t.Errorf("Response code should be Ok, was: %s", w.Code) + t.Errorf("Response code should be Ok, was: %d", w.Code) } if len(bodyAsString) == 0 { t.Errorf("Got empty body instead of file tree") diff --git a/recovery_test.go b/recovery_test.go index f9047e24..807146f3 100644 --- a/recovery_test.go +++ b/recovery_test.go @@ -28,7 +28,7 @@ func TestPanicInHandler(t *testing.T) { log.SetOutput(os.Stderr) if w.Code != 500 { - t.Errorf("Response code should be Internal Server Error, was: %s", w.Code) + t.Errorf("Response code should be Internal Server Error, was: %d", w.Code) } } @@ -51,6 +51,6 @@ func TestPanicWithAbort(t *testing.T) { // TEST if w.Code != 500 { - t.Errorf("Response code should be Bad request, was: %s", w.Code) + t.Errorf("Response code should be Bad request, was: %d", w.Code) } } diff --git a/utils.go b/utils.go index 43ddaecd..1fc0d70f 100644 --- a/utils.go +++ b/utils.go @@ -56,17 +56,16 @@ func chooseData(custom, wildcard interface{}) interface{} { return custom } -func parseAccept(accept string) []string { - parts := strings.Split(accept, ",") +func parseAccept(acceptHeader string) (parts []string) { + parts = strings.Split(acceptHeader, ",") for i, part := range parts { index := strings.IndexByte(part, ';') if index >= 0 { part = part[0:index] } - part = strings.TrimSpace(part) - parts[i] = part + parts[i] = strings.TrimSpace(part) } - return parts + return } func lastChar(str string) uint8 {