Procházet zdrojové kódy

Some cosmetic changes

Manu Mtz-Almeida před 10 roky
rodič
revize
615c62d736
4 změnil soubory, kde provedl 12 přidání a 18 odebrání
  1. 5 10
      gin.go
  2. 1 1
      gin_test.go
  3. 2 2
      recovery_test.go
  4. 4 5
      utils.go

+ 5 - 10
gin.go

@@ -5,12 +5,13 @@
 package gin
 package gin
 
 
 import (
 import (
-	"github.com/gin-gonic/gin/render"
-	"github.com/julienschmidt/httprouter"
 	"html/template"
 	"html/template"
 	"math"
 	"math"
 	"net/http"
 	"net/http"
 	"sync"
 	"sync"
+
+	"github.com/gin-gonic/gin/render"
+	"github.com/julienschmidt/httprouter"
 )
 )
 
 
 const (
 const (
@@ -158,16 +159,10 @@ func (engine *Engine) ServeHTTP(writer http.ResponseWriter, request *http.Reques
 
 
 func (engine *Engine) Run(addr string) error {
 func (engine *Engine) Run(addr string) error {
 	debugPrint("Listening and serving HTTP on %s\n", addr)
 	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 {
 func (engine *Engine) RunTLS(addr string, cert string, key string) error {
 	debugPrint("Listening and serving HTTPS on %s\n", addr)
 	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)
 }
 }

+ 1 - 1
gin_test.go

@@ -192,7 +192,7 @@ func TestHandleHeadToDir(t *testing.T) {
 	// TEST
 	// TEST
 	bodyAsString := w.Body.String()
 	bodyAsString := w.Body.String()
 	if w.Code != 200 {
 	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 {
 	if len(bodyAsString) == 0 {
 		t.Errorf("Got empty body instead of file tree")
 		t.Errorf("Got empty body instead of file tree")

+ 2 - 2
recovery_test.go

@@ -28,7 +28,7 @@ func TestPanicInHandler(t *testing.T) {
 	log.SetOutput(os.Stderr)
 	log.SetOutput(os.Stderr)
 
 
 	if w.Code != 500 {
 	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
 	// TEST
 	if w.Code != 500 {
 	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)
 	}
 	}
 }
 }

+ 4 - 5
utils.go

@@ -56,17 +56,16 @@ func chooseData(custom, wildcard interface{}) interface{} {
 	return custom
 	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 {
 	for i, part := range parts {
 		index := strings.IndexByte(part, ';')
 		index := strings.IndexByte(part, ';')
 		if index >= 0 {
 		if index >= 0 {
 			part = part[0:index]
 			part = part[0:index]
 		}
 		}
-		part = strings.TrimSpace(part)
-		parts[i] = part
+		parts[i] = strings.TrimSpace(part)
 	}
 	}
-	return parts
+	return
 }
 }
 
 
 func lastChar(str string) uint8 {
 func lastChar(str string) uint8 {