Merge branch 'master' into up-readme-for-website

This commit is contained in:
田欧 2019-03-14 12:00:20 +08:00 committed by GitHub
commit 3272aa52ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 36 additions and 12 deletions

View File

@ -1,22 +1,20 @@
language: go
sudo: false
go:
- 1.6.x
- 1.7.x
- 1.8.x
- 1.9.x
- 1.10.x
- 1.11.x
- 1.12.x
- master
matrix:
fast_finish: true
include:
- go: 1.6.x
- go: 1.7.x
- go: 1.8.x
- go: 1.9.x
- go: 1.10.x
- go: 1.11.x
env: GO111MODULE=on
- go: 1.12.x
env: GO111MODULE=on
- go: master
env: GO111MODULE=on
git:
depth: 10

View File

@ -13,7 +13,7 @@
Gin is a web framework written in Go (Golang). It features a martini-like API with much better performance, up to 40 times faster thanks to [httprouter](https://github.com/julienschmidt/httprouter). If you need performance and good productivity, you will love Gin.
The key features of Gin are:
**The key features of Gin are:**
- Zero allocation router
- Fast

View File

@ -66,6 +66,8 @@ type LogFormatterParams struct {
IsTerm bool
// BodySize is the size of the Response Body
BodySize int
// Keys are the keys set on the request's context.
Keys map[string]interface{}
}
// StatusCodeColor is the ANSI color for appropriately logging http status code to a terminal.
@ -227,6 +229,7 @@ func LoggerWithConfig(conf LoggerConfig) HandlerFunc {
param := LogFormatterParams{
Request: c.Request,
IsTerm: isTerm,
Keys: c.Keys,
}
// Stop timer

View File

@ -181,6 +181,7 @@ func TestLoggerWithFormatter(t *testing.T) {
func TestLoggerWithConfigFormatting(t *testing.T) {
var gotParam LogFormatterParams
var gotKeys map[string]interface{}
buffer := new(bytes.Buffer)
router := New()
@ -204,6 +205,7 @@ func TestLoggerWithConfigFormatting(t *testing.T) {
router.GET("/example", func(c *Context) {
// set dummy ClientIP
c.Request.Header.Set("X-Forwarded-For", "20.20.20.20")
gotKeys = c.Keys
})
performRequest(router, "GET", "/example?a=100")
@ -223,6 +225,7 @@ func TestLoggerWithConfigFormatting(t *testing.T) {
assert.Equal(t, "GET", gotParam.Method)
assert.Equal(t, "/example?a=100", gotParam.Path)
assert.Empty(t, gotParam.ErrorMessage)
assert.Equal(t, gotKeys, gotParam.Keys)
}

View File

@ -195,7 +195,7 @@ func (group *RouterGroup) createStaticHandler(relativePath string, fs http.FileS
// Check if file exists and/or if we have permission to access it
if _, err := fs.Open(file); err != nil {
c.Writer.WriteHeader(http.StatusNotFound)
c.handlers = group.engine.allNoRoute
c.handlers = group.engine.noRoute
// Reset index
c.index = -1
return

View File

@ -429,7 +429,6 @@ func TestRouterNotFound(t *testing.T) {
func TestRouterStaticFSNotFound(t *testing.T) {
router := New()
router.StaticFS("/", http.FileSystem(http.Dir("/thisreallydoesntexist/")))
router.NoRoute(func(c *Context) {
c.String(404, "non existent")
@ -452,6 +451,27 @@ func TestRouterStaticFSFileNotFound(t *testing.T) {
})
}
// Reproduction test for the bug of issue #1805
func TestMiddlewareCalledOnceByRouterStaticFSNotFound(t *testing.T) {
router := New()
// Middleware must be called just only once by per request.
middlewareCalledNum := 0
router.Use(func(c *Context) {
middlewareCalledNum += 1
})
router.StaticFS("/", http.FileSystem(http.Dir("/thisreallydoesntexist/")))
// First access
performRequest(router, "GET", "/nonexistent")
assert.Equal(t, 1, middlewareCalledNum)
// Second access
performRequest(router, "HEAD", "/nonexistent")
assert.Equal(t, 2, middlewareCalledNum)
}
func TestRouteRawPath(t *testing.T) {
route := New()
route.UseRawPath = true

BIN
testdata/assets/console.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB