Merge branch 'master' into mapping_array

This commit is contained in:
田欧 2019-03-11 08:15:15 +08:00 committed by GitHub
commit 5b04823aaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 9 deletions

View File

@ -1,22 +1,20 @@
language: go language: go
sudo: false 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: matrix:
fast_finish: true fast_finish: true
include: 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 - go: 1.11.x
env: GO111MODULE=on env: GO111MODULE=on
- go: 1.12.x - go: 1.12.x
env: GO111MODULE=on env: GO111MODULE=on
- go: master
env: GO111MODULE=on
git: git:
depth: 10 depth: 10

View File

@ -66,6 +66,8 @@ type LogFormatterParams struct {
IsTerm bool IsTerm bool
// BodySize is the size of the Response Body // BodySize is the size of the Response Body
BodySize int 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. // 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{ param := LogFormatterParams{
Request: c.Request, Request: c.Request,
IsTerm: isTerm, IsTerm: isTerm,
Keys: c.Keys,
} }
// Stop timer // Stop timer

View File

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