Some cosmetic changes

This commit is contained in:
Manu Mtz-Almeida 2015-03-23 04:41:29 +01:00
parent c8ee142717
commit 615c62d736
4 changed files with 12 additions and 18 deletions

15
gin.go
View File

@ -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 http.ListenAndServe(addr, engine)
return err
}
return nil
} }
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 http.ListenAndServeTLS(addr, cert, key, engine)
return err
}
return nil
} }

View File

@ -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")

View File

@ -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)
} }
} }

View File

@ -56,17 +56,16 @@ func chooseData(custom, wildcard interface{}) interface{} {
return custom return custom
} }
func parseAccept(accept string) []string { func parseAccept(acceptHeader string) (parts []string) {
parts := strings.Split(accept, ",") 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] = strings.TrimSpace(part)
parts[i] = part
} }
return parts return
} }
func lastChar(str string) uint8 { func lastChar(str string) uint8 {