Cosmetic changes
This commit is contained in:
		@ -76,7 +76,7 @@ func TestBasicAuth401WithCustomRealm(t *testing.T) {
 | 
				
			|||||||
	r.ServeHTTP(w, req)
 | 
						r.ServeHTTP(w, req)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if w.Code != 401 {
 | 
						if w.Code != 401 {
 | 
				
			||||||
		t.Errorf("Response code should be Not autorized, was: %s", w.Code)
 | 
							t.Errorf("Response code should be Not autorized, was: %d", w.Code)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if w.HeaderMap.Get("WWW-Authenticate") != "Basic realm=\"My Custom Realm\"" {
 | 
						if w.HeaderMap.Get("WWW-Authenticate") != "Basic realm=\"My Custom Realm\"" {
 | 
				
			||||||
 | 
				
			|||||||
@ -362,7 +362,7 @@ func (c *Context) Redirect(code int, location string) {
 | 
				
			|||||||
	if code >= 300 && code <= 308 {
 | 
						if code >= 300 && code <= 308 {
 | 
				
			||||||
		c.Render(code, render.Redirect, location)
 | 
							c.Render(code, render.Redirect, location)
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		panic(fmt.Sprintf("Cannot send a redirect with status code %d", code))
 | 
							log.Panicf("Cannot send a redirect with status code %d", code)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										25
									
								
								debug.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								debug.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,25 @@
 | 
				
			|||||||
 | 
					// Copyright 2014 Manu Martinez-Almeida.  All rights reserved.
 | 
				
			||||||
 | 
					// Use of this source code is governed by a MIT style
 | 
				
			||||||
 | 
					// license that can be found in the LICENSE file.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					package gin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import "log"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func IsDebugging() bool {
 | 
				
			||||||
 | 
						return gin_mode == debugCode
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func debugRoute(httpMethod, absolutePath string, handlers []HandlerFunc) {
 | 
				
			||||||
 | 
						if IsDebugging() {
 | 
				
			||||||
 | 
							nuHandlers := len(handlers)
 | 
				
			||||||
 | 
							handlerName := nameOfFunction(handlers[nuHandlers-1])
 | 
				
			||||||
 | 
							debugPrint("%-5s %-25s --> %s (%d handlers)\n", httpMethod, absolutePath, handlerName, nuHandlers)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func debugPrint(format string, values ...interface{}) {
 | 
				
			||||||
 | 
						if IsDebugging() {
 | 
				
			||||||
 | 
							log.Printf("[GIN-debug] "+format, values...)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -5,8 +5,9 @@
 | 
				
			|||||||
package gin
 | 
					package gin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"github.com/gin-gonic/gin/binding"
 | 
					 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/gin-gonic/gin/binding"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// DEPRECATED, use Bind() instead.
 | 
					// DEPRECATED, use Bind() instead.
 | 
				
			||||||
 | 
				
			|||||||
@ -5,9 +5,10 @@
 | 
				
			|||||||
package gin
 | 
					package gin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"github.com/mattn/go-colorable"
 | 
					 | 
				
			||||||
	"log"
 | 
						"log"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/mattn/go-colorable"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var (
 | 
					var (
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										10
									
								
								mode.go
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								mode.go
									
									
									
									
									
								
							@ -51,13 +51,3 @@ func SetMode(value string) {
 | 
				
			|||||||
func Mode() string {
 | 
					func Mode() string {
 | 
				
			||||||
	return mode_name
 | 
						return mode_name
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
func IsDebugging() bool {
 | 
					 | 
				
			||||||
	return gin_mode == debugCode
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func debugPrint(format string, values ...interface{}) {
 | 
					 | 
				
			||||||
	if IsDebugging() {
 | 
					 | 
				
			||||||
		log.Printf("[GIN-debug] "+format, values...)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
				
			|||||||
@ -5,9 +5,10 @@
 | 
				
			|||||||
package gin
 | 
					package gin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"github.com/julienschmidt/httprouter"
 | 
					 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
	"path"
 | 
						"path"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/julienschmidt/httprouter"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Used internally to configure router, a RouterGroup is associated with a prefix
 | 
					// Used internally to configure router, a RouterGroup is associated with a prefix
 | 
				
			||||||
@ -46,11 +47,7 @@ func (group *RouterGroup) Group(relativePath string, handlers ...HandlerFunc) *R
 | 
				
			|||||||
func (group *RouterGroup) Handle(httpMethod, relativePath string, handlers []HandlerFunc) {
 | 
					func (group *RouterGroup) Handle(httpMethod, relativePath string, handlers []HandlerFunc) {
 | 
				
			||||||
	absolutePath := group.calculateAbsolutePath(relativePath)
 | 
						absolutePath := group.calculateAbsolutePath(relativePath)
 | 
				
			||||||
	handlers = group.combineHandlers(handlers)
 | 
						handlers = group.combineHandlers(handlers)
 | 
				
			||||||
	if IsDebugging() {
 | 
						debugRoute(httpMethod, absolutePath, handlers)
 | 
				
			||||||
		nuHandlers := len(handlers)
 | 
					 | 
				
			||||||
		handlerName := nameOfFunction(handlers[nuHandlers-1])
 | 
					 | 
				
			||||||
		debugPrint("%-5s %-25s --> %s (%d handlers)\n", httpMethod, absolutePath, handlerName, nuHandlers)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	group.engine.router.Handle(httpMethod, absolutePath, func(w http.ResponseWriter, req *http.Request, params httprouter.Params) {
 | 
						group.engine.router.Handle(httpMethod, absolutePath, func(w http.ResponseWriter, req *http.Request, params httprouter.Params) {
 | 
				
			||||||
		context := group.engine.createContext(w, req, params, handlers)
 | 
							context := group.engine.createContext(w, req, params, handlers)
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user