From d7776de7d444935ea4385999711bd6331a98fecb Mon Sep 17 00:00:00 2001 From: Laurent Caumont <40688874+laurentcau@users.noreply.github.com> Date: Tue, 27 Jan 2026 03:09:01 +0100 Subject: [PATCH 01/70] feat(render): add bson protocol (#4145) --- binding/binding.go | 4 ++++ binding/binding_nomsgpack.go | 4 ++++ binding/binding_test.go | 16 ++++++++++++++++ binding/bson.go | 30 ++++++++++++++++++++++++++++++ context.go | 11 +++++++++++ context_test.go | 18 ++++++++++++++++++ go.mod | 13 +++++++++---- go.sum | 17 ++++++++++------- render/bson.go | 34 ++++++++++++++++++++++++++++++++++ render/render_test.go | 26 ++++++++++++++++++++++++++ 10 files changed, 162 insertions(+), 11 deletions(-) create mode 100644 binding/bson.go create mode 100644 render/bson.go diff --git a/binding/binding.go b/binding/binding.go index 702d0e82..eced0ae2 100644 --- a/binding/binding.go +++ b/binding/binding.go @@ -23,6 +23,7 @@ const ( MIMEYAML = "application/x-yaml" MIMEYAML2 = "application/yaml" MIMETOML = "application/toml" + MIMEBSON = "application/bson" ) // Binding describes the interface which needs to be implemented for binding the @@ -86,6 +87,7 @@ var ( Header Binding = headerBinding{} Plain BindingBody = plainBinding{} TOML BindingBody = tomlBinding{} + BSON BindingBody = bsonBinding{} ) // Default returns the appropriate Binding instance based on the HTTP method @@ -110,6 +112,8 @@ func Default(method, contentType string) Binding { return TOML case MIMEMultipartPOSTForm: return FormMultipart + case MIMEBSON: + return BSON default: // case MIMEPOSTForm: return Form } diff --git a/binding/binding_nomsgpack.go b/binding/binding_nomsgpack.go index c8e61310..ae364d79 100644 --- a/binding/binding_nomsgpack.go +++ b/binding/binding_nomsgpack.go @@ -21,6 +21,7 @@ const ( MIMEYAML = "application/x-yaml" MIMEYAML2 = "application/yaml" MIMETOML = "application/toml" + MIMEBSON = "application/bson" ) // Binding describes the interface which needs to be implemented for binding the @@ -82,6 +83,7 @@ var ( Header = headerBinding{} TOML = tomlBinding{} Plain = plainBinding{} + BSON BindingBody = bsonBinding{} ) // Default returns the appropriate Binding instance based on the HTTP method @@ -104,6 +106,8 @@ func Default(method, contentType string) Binding { return FormMultipart case MIMETOML: return TOML + case MIMEBSON: + return BSON default: // case MIMEPOSTForm: return Form } diff --git a/binding/binding_test.go b/binding/binding_test.go index 07619ebf..a9f8b9e3 100644 --- a/binding/binding_test.go +++ b/binding/binding_test.go @@ -21,6 +21,7 @@ import ( "github.com/gin-gonic/gin/testdata/protoexample" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.mongodb.org/mongo-driver/bson" "google.golang.org/protobuf/proto" ) @@ -172,6 +173,9 @@ func TestBindingDefault(t *testing.T) { assert.Equal(t, TOML, Default(http.MethodPost, MIMETOML)) assert.Equal(t, TOML, Default(http.MethodPut, MIMETOML)) + + assert.Equal(t, BSON, Default(http.MethodPost, MIMEBSON)) + assert.Equal(t, BSON, Default(http.MethodPut, MIMEBSON)) } func TestBindingJSONNilBody(t *testing.T) { @@ -731,6 +735,18 @@ func TestBindingProtoBufFail(t *testing.T) { string(data), string(data[1:])) } +func TestBindingBSON(t *testing.T) { + var obj FooStruct + obj.Foo = "bar" + data, _ := bson.Marshal(&obj) + testBodyBinding(t, + BSON, "bson", + "/", "/", + string(data), + // note: for badbody, we remove first byte to make it invalid + string(data[1:])) +} + func TestValidationFails(t *testing.T) { var obj FooStruct req := requestWithBody(http.MethodPost, "/", `{"bar": "foo"}`) diff --git a/binding/bson.go b/binding/bson.go new file mode 100644 index 00000000..4a698247 --- /dev/null +++ b/binding/bson.go @@ -0,0 +1,30 @@ +// Copyright 2025 Gin Core Team. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + +package binding + +import ( + "io" + "net/http" + + "go.mongodb.org/mongo-driver/bson" +) + +type bsonBinding struct{} + +func (bsonBinding) Name() string { + return "bson" +} + +func (b bsonBinding) Bind(req *http.Request, obj any) error { + buf, err := io.ReadAll(req.Body) + if err == nil { + err = b.BindBody(buf, obj) + } + return err +} + +func (bsonBinding) BindBody(body []byte, obj any) error { + return bson.Unmarshal(body, obj) +} diff --git a/context.go b/context.go index c7bc61fe..d73f59e3 100644 --- a/context.go +++ b/context.go @@ -40,6 +40,7 @@ const ( MIMEYAML2 = binding.MIMEYAML2 MIMETOML = binding.MIMETOML MIMEPROTOBUF = binding.MIMEPROTOBUF + MIMEBSON = binding.MIMEBSON ) // BodyBytesKey indicates a default body bytes key. @@ -1237,6 +1238,11 @@ func (c *Context) ProtoBuf(code int, obj any) { c.Render(code, render.ProtoBuf{Data: obj}) } +// BSON serializes the given struct as BSON into the response body. +func (c *Context) BSON(code int, obj any) { + c.Render(code, render.BSON{Data: obj}) +} + // String writes the given string into the response body. func (c *Context) String(code int, format string, values ...any) { c.Render(code, render.String{Format: format, Data: values}) @@ -1344,6 +1350,7 @@ type Negotiate struct { Data any TOMLData any PROTOBUFData any + BSONData any } // Negotiate calls different Render according to acceptable Accept format. @@ -1373,6 +1380,10 @@ func (c *Context) Negotiate(code int, config Negotiate) { data := chooseData(config.PROTOBUFData, config.Data) c.ProtoBuf(code, data) + case binding.MIMEBSON: + data := chooseData(config.BSONData, config.Data) + c.BSON(code, data) + default: c.AbortWithError(http.StatusNotAcceptable, errors.New("the accepted formats are not offered by the server")) //nolint: errcheck } diff --git a/context_test.go b/context_test.go index cb534884..41694585 100644 --- a/context_test.go +++ b/context_test.go @@ -32,6 +32,7 @@ import ( testdata "github.com/gin-gonic/gin/testdata/protoexample" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.mongodb.org/mongo-driver/bson" "google.golang.org/protobuf/proto" ) @@ -1701,6 +1702,23 @@ func TestContextNegotiationWithPROTOBUF(t *testing.T) { assert.Equal(t, "application/x-protobuf", w.Header().Get("Content-Type")) } +func TestContextNegotiationWithBSON(t *testing.T) { + w := httptest.NewRecorder() + c, _ := CreateTestContext(w) + c.Request, _ = http.NewRequest(http.MethodPost, "", nil) + + c.Negotiate(http.StatusOK, Negotiate{ + Offered: []string{MIMEBSON, MIMEXML, MIMEJSON, MIMEYAML, MIMEYAML2}, + Data: H{"foo": "bar"}, + }) + + bData, _ := bson.Marshal(H{"foo": "bar"}) + + assert.Equal(t, http.StatusOK, w.Code) + assert.Equal(t, string(bData), w.Body.String()) + assert.Equal(t, "application/bson", w.Header().Get("Content-Type")) +} + func TestContextNegotiationNotSupport(t *testing.T) { w := httptest.NewRecorder() c, _ := CreateTestContext(w) diff --git a/go.mod b/go.mod index b755e40d..425c7a7f 100644 --- a/go.mod +++ b/go.mod @@ -2,11 +2,13 @@ module github.com/gin-gonic/gin go 1.24.0 +toolchain go1.24.7 + require ( github.com/bytedance/sonic v1.14.2 github.com/gin-contrib/sse v1.1.0 github.com/go-playground/validator/v10 v10.28.0 - github.com/goccy/go-json v0.10.2 + github.com/goccy/go-json v0.10.5 github.com/goccy/go-yaml v1.19.1 github.com/json-iterator/go v1.1.12 github.com/mattn/go-isatty v0.0.20 @@ -15,10 +17,13 @@ require ( github.com/quic-go/quic-go v0.57.1 github.com/stretchr/testify v1.11.1 github.com/ugorji/go/codec v1.3.1 + go.mongodb.org/mongo-driver v1.17.7 golang.org/x/net v0.47.0 google.golang.org/protobuf v1.36.10 ) +require gopkg.in/yaml.v3 v3.0.1 // indirect + require ( github.com/bytedance/gopkg v0.1.3 // indirect github.com/bytedance/sonic/loader v0.4.0 // indirect @@ -30,13 +35,13 @@ require ( github.com/klauspost/cpuid/v2 v2.3.0 // indirect github.com/kr/text v0.2.0 // indirect github.com/leodido/go-urn v1.4.0 // indirect - github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/quic-go/qpack v0.6.0 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect - golang.org/x/arch v0.20.0 // indirect + go.uber.org/mock v0.6.0 // indirect + golang.org/x/arch v0.22.0 // indirect golang.org/x/crypto v0.45.0 // indirect golang.org/x/sys v0.38.0 // indirect golang.org/x/text v0.31.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 06442efb..2a6cb14c 100644 --- a/go.sum +++ b/go.sum @@ -22,8 +22,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= github.com/go-playground/validator/v10 v10.28.0 h1:Q7ibns33JjyW48gHkuFT91qX48KG0ktULL6FgHdG688= github.com/go-playground/validator/v10 v10.28.0/go.mod h1:GoI6I1SjPBh9p7ykNE/yj3fFYbyDOpwMn5KXd+m2hUU= -github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= -github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4= +github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= github.com/goccy/go-yaml v1.19.1 h1:3rG3+v8pkhRqoQ/88NYNMHYVGYztCOCIZ7UQhu7H+NE= github.com/goccy/go-yaml v1.19.1/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= @@ -41,8 +41,9 @@ github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4= @@ -70,10 +71,12 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go/codec v1.3.1 h1:waO7eEiFDwidsBN6agj1vJQ4AG7lh2yqXyOXqhgQuyY= github.com/ugorji/go/codec v1.3.1/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4= -go.uber.org/mock v0.5.2 h1:LbtPTcP8A5k9WPXj54PPPbjcI4Y6lhyOZXn+VS7wNko= -go.uber.org/mock v0.5.2/go.mod h1:wLlUxC2vVTPTaE3UD51E0BGOAElKrILxhVSDYQLld5o= -golang.org/x/arch v0.20.0 h1:dx1zTU0MAE98U+TQ8BLl7XsJbgze2WnNKF/8tGp/Q6c= -golang.org/x/arch v0.20.0/go.mod h1:bdwinDaKcfZUGpH09BB7ZmOfhalA8lQdzl62l8gGWsk= +go.mongodb.org/mongo-driver v1.17.7 h1:a9w+U3Vt67eYzcfq3k/OAv284/uUUkL0uP75VE5rCOU= +go.mongodb.org/mongo-driver v1.17.7/go.mod h1:Hy04i7O2kC4RS06ZrhPRqj/u4DTYkFDAAccj+rVKqgQ= +go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y= +go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU= +golang.org/x/arch v0.22.0 h1:c/Zle32i5ttqRXjdLyyHZESLD/bB90DCU1g9l/0YBDI= +golang.org/x/arch v0.22.0/go.mod h1:dNHoOeKiyja7GTvF9NJS1l3Z2yntpQNzgrjh1cU103A= golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q= golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4= golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY= diff --git a/render/bson.go b/render/bson.go new file mode 100644 index 00000000..7332b8b2 --- /dev/null +++ b/render/bson.go @@ -0,0 +1,34 @@ +// Copyright 2025 Gin Core Team. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + +package render + +import ( + "net/http" + + "go.mongodb.org/mongo-driver/bson" +) + +// BSON contains the given interface object. +type BSON struct { + Data any +} + +var bsonContentType = []string{"application/bson"} + +// Render (BSON) marshals the given interface object and writes data with custom ContentType. +func (r BSON) Render(w http.ResponseWriter) error { + r.WriteContentType(w) + + bytes, err := bson.Marshal(&r.Data) + if err == nil { + _, err = w.Write(bytes) + } + return err +} + +// WriteContentType (BSONBuf) writes BSONBuf ContentType. +func (r BSON) WriteContentType(w http.ResponseWriter) { + writeContentType(w, bsonContentType) +} diff --git a/render/render_test.go b/render/render_test.go index d9ae2067..7213e48f 100644 --- a/render/render_test.go +++ b/render/render_test.go @@ -19,6 +19,7 @@ import ( testdata "github.com/gin-gonic/gin/testdata/protoexample" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.mongodb.org/mongo-driver/bson" "google.golang.org/protobuf/proto" ) @@ -359,6 +360,31 @@ func TestRenderProtoBufFail(t *testing.T) { require.Error(t, err) } +func TestRenderBSON(t *testing.T) { + w := httptest.NewRecorder() + reps := []int64{int64(1), int64(2)} + type mystruct struct { + Label string + Reps []int64 + } + + data := &mystruct{ + Label: "test", + Reps: reps, + } + + (BSON{data}).WriteContentType(w) + bsonData, err := bson.Marshal(data) + require.NoError(t, err) + assert.Equal(t, "application/bson", w.Header().Get("Content-Type")) + + err = (BSON{data}).Render(w) + + require.NoError(t, err) + assert.Equal(t, bsonData, w.Body.Bytes()) + assert.Equal(t, "application/bson", w.Header().Get("Content-Type")) +} + func TestRenderXML(t *testing.T) { w := httptest.NewRecorder() data := xmlmap{ From 8e07d37c63e5536eb25f4af4c91eabeee4011fba Mon Sep 17 00:00:00 2001 From: Mahan Adhikari <41227164+mahanadh@users.noreply.github.com> Date: Fri, 13 Feb 2026 11:39:14 +0545 Subject: [PATCH 02/70] fix: Correct typos, improve documentation clarity, and remove dead code (#4511) * fix: correct typos and improve documentation clarity - Fix typo "Oupps" to "Oops" in recovery test panic messages - Fix confusing documentation in Bind() and ShouldBind() methods that incorrectly stated "JSON or XML as a JSON input" - Remove double period in StaticFileFS documentation comment - Remove unused ErrorTypeNu constant that had duplicate comment with ErrorTypeAny and was never used in the codebase * tech: Fix the pull request routing link --- CONTRIBUTING.md | 2 +- context.go | 8 ++++---- errors.go | 2 -- recovery_test.go | 26 +++++++++++++------------- routergroup.go | 2 +- 5 files changed, 19 insertions(+), 21 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9703d6b4..3b05a160 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -36,6 +36,6 @@ Please ensure your pull request meets the following requirements: - All tests pass in available continuous integration systems (e.g., GitHub Actions). - Add or modify tests to cover your code changes. - If your pull request introduces a new feature, document it in [`docs/doc.md`](docs/doc.md), not in the README. -- Follow the checklist in the [Pull Request Template](.github/PULL_REQUEST_TEMPLATE.md:1). +- Follow the checklist in the [Pull Request Template](.github/PULL_REQUEST_TEMPLATE.md). Thank you for contributing! diff --git a/context.go b/context.go index d73f59e3..282fb9ac 100644 --- a/context.go +++ b/context.go @@ -751,8 +751,8 @@ func (c *Context) SaveUploadedFile(file *multipart.FileHeader, dst string, perm // "application/json" --> JSON binding // "application/xml" --> XML binding // -// It parses the request's body as JSON if Content-Type == "application/json" using JSON or XML as a JSON input. -// It decodes the json payload into the struct specified as a pointer. +// It parses the request's body based on the Content-Type (e.g., JSON or XML). +// It decodes the payload into the struct specified as a pointer. // It writes a 400 error and sets Content-Type header "text/plain" in the response if input is not valid. func (c *Context) Bind(obj any) error { b := binding.Default(c.Request.Method, c.ContentType()) @@ -832,8 +832,8 @@ func (c *Context) MustBindWith(obj any, b binding.Binding) error { // "application/json" --> JSON binding // "application/xml" --> XML binding // -// It parses the request's body as JSON if Content-Type == "application/json" using JSON or XML as a JSON input. -// It decodes the json payload into the struct specified as a pointer. +// It parses the request's body based on the Content-Type (e.g., JSON or XML). +// It decodes the payload into the struct specified as a pointer. // Like c.Bind() but this method does not set the response status code to 400 or abort if input is not valid. func (c *Context) ShouldBind(obj any) error { b := binding.Default(c.Request.Method, c.ContentType()) diff --git a/errors.go b/errors.go index 829e9d2c..c0d907b9 100644 --- a/errors.go +++ b/errors.go @@ -26,8 +26,6 @@ const ( ErrorTypePublic ErrorType = 1 << 1 // ErrorTypeAny indicates any other error. ErrorTypeAny ErrorType = 1<<64 - 1 - // ErrorTypeNu indicates any other error. - ErrorTypeNu = 2 ) // Error represents a error's specification. diff --git a/recovery_test.go b/recovery_test.go index 0faa3280..028c4ad6 100644 --- a/recovery_test.go +++ b/recovery_test.go @@ -22,7 +22,7 @@ func TestPanicClean(t *testing.T) { router.Use(RecoveryWithWriter(buffer)) router.GET("/recovery", func(c *Context) { c.AbortWithStatus(http.StatusBadRequest) - panic("Oupps, Houston, we have a problem") + panic("Oops, Houston, we have a problem") }) // RUN w := PerformRequest(router, http.MethodGet, "/recovery", @@ -52,14 +52,14 @@ func TestPanicInHandler(t *testing.T) { router := New() router.Use(RecoveryWithWriter(buffer)) router.GET("/recovery", func(_ *Context) { - panic("Oupps, Houston, we have a problem") + panic("Oops, Houston, we have a problem") }) // RUN w := PerformRequest(router, http.MethodGet, "/recovery") // TEST assert.Equal(t, http.StatusInternalServerError, w.Code) assert.Contains(t, buffer.String(), "panic recovered") - assert.Contains(t, buffer.String(), "Oupps, Houston, we have a problem") + assert.Contains(t, buffer.String(), "Oops, Houston, we have a problem") assert.Contains(t, buffer.String(), t.Name()) assert.NotContains(t, buffer.String(), "GET /recovery") @@ -80,7 +80,7 @@ func TestPanicWithAbort(t *testing.T) { router.Use(RecoveryWithWriter(nil)) router.GET("/recovery", func(c *Context) { c.AbortWithStatus(http.StatusBadRequest) - panic("Oupps, Houston, we have a problem") + panic("Oops, Houston, we have a problem") }) // RUN w := PerformRequest(router, http.MethodGet, "/recovery") @@ -162,14 +162,14 @@ func TestCustomRecoveryWithWriter(t *testing.T) { } router.Use(CustomRecoveryWithWriter(buffer, handleRecovery)) router.GET("/recovery", func(_ *Context) { - panic("Oupps, Houston, we have a problem") + panic("Oops, Houston, we have a problem") }) // RUN w := PerformRequest(router, http.MethodGet, "/recovery") // TEST assert.Equal(t, http.StatusBadRequest, w.Code) assert.Contains(t, buffer.String(), "panic recovered") - assert.Contains(t, buffer.String(), "Oupps, Houston, we have a problem") + assert.Contains(t, buffer.String(), "Oops, Houston, we have a problem") assert.Contains(t, buffer.String(), t.Name()) assert.NotContains(t, buffer.String(), "GET /recovery") @@ -181,7 +181,7 @@ func TestCustomRecoveryWithWriter(t *testing.T) { assert.Equal(t, http.StatusBadRequest, w.Code) assert.Contains(t, buffer.String(), "GET /recovery") - assert.Equal(t, strings.Repeat("Oupps, Houston, we have a problem", 2), errBuffer.String()) + assert.Equal(t, strings.Repeat("Oops, Houston, we have a problem", 2), errBuffer.String()) SetMode(TestMode) } @@ -197,14 +197,14 @@ func TestCustomRecovery(t *testing.T) { } router.Use(CustomRecovery(handleRecovery)) router.GET("/recovery", func(_ *Context) { - panic("Oupps, Houston, we have a problem") + panic("Oops, Houston, we have a problem") }) // RUN w := PerformRequest(router, http.MethodGet, "/recovery") // TEST assert.Equal(t, http.StatusBadRequest, w.Code) assert.Contains(t, buffer.String(), "panic recovered") - assert.Contains(t, buffer.String(), "Oupps, Houston, we have a problem") + assert.Contains(t, buffer.String(), "Oops, Houston, we have a problem") assert.Contains(t, buffer.String(), t.Name()) assert.NotContains(t, buffer.String(), "GET /recovery") @@ -216,7 +216,7 @@ func TestCustomRecovery(t *testing.T) { assert.Equal(t, http.StatusBadRequest, w.Code) assert.Contains(t, buffer.String(), "GET /recovery") - assert.Equal(t, strings.Repeat("Oupps, Houston, we have a problem", 2), errBuffer.String()) + assert.Equal(t, strings.Repeat("Oops, Houston, we have a problem", 2), errBuffer.String()) SetMode(TestMode) } @@ -232,14 +232,14 @@ func TestRecoveryWithWriterWithCustomRecovery(t *testing.T) { } router.Use(RecoveryWithWriter(DefaultErrorWriter, handleRecovery)) router.GET("/recovery", func(_ *Context) { - panic("Oupps, Houston, we have a problem") + panic("Oops, Houston, we have a problem") }) // RUN w := PerformRequest(router, http.MethodGet, "/recovery") // TEST assert.Equal(t, http.StatusBadRequest, w.Code) assert.Contains(t, buffer.String(), "panic recovered") - assert.Contains(t, buffer.String(), "Oupps, Houston, we have a problem") + assert.Contains(t, buffer.String(), "Oops, Houston, we have a problem") assert.Contains(t, buffer.String(), t.Name()) assert.NotContains(t, buffer.String(), "GET /recovery") @@ -251,7 +251,7 @@ func TestRecoveryWithWriterWithCustomRecovery(t *testing.T) { assert.Equal(t, http.StatusBadRequest, w.Code) assert.Contains(t, buffer.String(), "GET /recovery") - assert.Equal(t, strings.Repeat("Oupps, Houston, we have a problem", 2), errBuffer.String()) + assert.Equal(t, strings.Repeat("Oops, Houston, we have a problem", 2), errBuffer.String()) SetMode(TestMode) } diff --git a/routergroup.go b/routergroup.go index b2540ec1..c01b917e 100644 --- a/routergroup.go +++ b/routergroup.go @@ -169,7 +169,7 @@ func (group *RouterGroup) StaticFile(relativePath, filepath string) IRoutes { }) } -// StaticFileFS works just like `StaticFile` but a custom `http.FileSystem` can be used instead.. +// StaticFileFS works just like `StaticFile` but a custom `http.FileSystem` can be used instead. // router.StaticFileFS("favicon.ico", "./resources/favicon.ico", Dir{".", false}) // Gin by default uses: gin.Dir() func (group *RouterGroup) StaticFileFS(relativePath, filepath string, fs http.FileSystem) IRoutes { From 488f8c3ffa579a8d19beb2bae95ff8ef36b3d53f Mon Sep 17 00:00:00 2001 From: Varun Chawla <34209028+veeceey@users.noreply.github.com> Date: Thu, 12 Feb 2026 21:55:23 -0800 Subject: [PATCH 03/70] refactor: replace magic numbers with named constants in bodyAllowedForStatus (#4529) Use http.StatusContinue and http.StatusOK instead of hardcoded 100 and 199 for the 1xx informational status range check, consistent with the pattern already used in logger.go. Fixes #4489 --- context.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/context.go b/context.go index 282fb9ac..a00d1e55 100644 --- a/context.go +++ b/context.go @@ -1058,7 +1058,7 @@ func (c *Context) requestHeader(key string) string { // bodyAllowedForStatus is a copy of http.bodyAllowedForStatus non-exported function. func bodyAllowedForStatus(status int) bool { switch { - case status >= 100 && status <= 199: + case status >= http.StatusContinue && status < http.StatusOK: return false case status == http.StatusNoContent: return false From 882f42b0ed7bbb0e5f381ea45ab8fa36638b85d8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Feb 2026 13:56:24 +0800 Subject: [PATCH 04/70] chore(deps): bump golang.org/x/net from 0.47.0 to 0.49.0 (#4508) Bumps [golang.org/x/net](https://github.com/golang/net) from 0.47.0 to 0.49.0. - [Commits](https://github.com/golang/net/compare/v0.47.0...v0.49.0) --- updated-dependencies: - dependency-name: golang.org/x/net dependency-version: 0.49.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 425c7a7f..1863f04c 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( github.com/stretchr/testify v1.11.1 github.com/ugorji/go/codec v1.3.1 go.mongodb.org/mongo-driver v1.17.7 - golang.org/x/net v0.47.0 + golang.org/x/net v0.49.0 google.golang.org/protobuf v1.36.10 ) @@ -41,7 +41,7 @@ require ( github.com/twitchyliquid64/golang-asm v0.15.1 // indirect go.uber.org/mock v0.6.0 // indirect golang.org/x/arch v0.22.0 // indirect - golang.org/x/crypto v0.45.0 // indirect - golang.org/x/sys v0.38.0 // indirect - golang.org/x/text v0.31.0 // indirect + golang.org/x/crypto v0.47.0 // indirect + golang.org/x/sys v0.40.0 // indirect + golang.org/x/text v0.33.0 // indirect ) diff --git a/go.sum b/go.sum index 2a6cb14c..9b17d180 100644 --- a/go.sum +++ b/go.sum @@ -77,15 +77,15 @@ go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y= go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU= golang.org/x/arch v0.22.0 h1:c/Zle32i5ttqRXjdLyyHZESLD/bB90DCU1g9l/0YBDI= golang.org/x/arch v0.22.0/go.mod h1:dNHoOeKiyja7GTvF9NJS1l3Z2yntpQNzgrjh1cU103A= -golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q= -golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4= -golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY= -golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU= +golang.org/x/crypto v0.47.0 h1:V6e3FRj+n4dbpw86FJ8Fv7XVOql7TEwpHapKoMJ/GO8= +golang.org/x/crypto v0.47.0/go.mod h1:ff3Y9VzzKbwSSEzWqJsJVBnWmRwRSHt/6Op5n9bQc4A= +golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o= +golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc= -golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= -golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM= -golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM= +golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ= +golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE= +golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8= golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE= golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg= google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE= From 71cefce08e9ee91f6fb841a668207ccfda1df169 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Feb 2026 13:56:40 +0800 Subject: [PATCH 05/70] chore(deps): bump github.com/goccy/go-yaml from 1.19.1 to 1.19.2 (#4507) Bumps [github.com/goccy/go-yaml](https://github.com/goccy/go-yaml) from 1.19.1 to 1.19.2. - [Release notes](https://github.com/goccy/go-yaml/releases) - [Changelog](https://github.com/goccy/go-yaml/blob/master/CHANGELOG.md) - [Commits](https://github.com/goccy/go-yaml/compare/v1.19.1...v1.19.2) --- updated-dependencies: - dependency-name: github.com/goccy/go-yaml dependency-version: 1.19.2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 1863f04c..0496bc80 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/gin-contrib/sse v1.1.0 github.com/go-playground/validator/v10 v10.28.0 github.com/goccy/go-json v0.10.5 - github.com/goccy/go-yaml v1.19.1 + github.com/goccy/go-yaml v1.19.2 github.com/json-iterator/go v1.1.12 github.com/mattn/go-isatty v0.0.20 github.com/modern-go/reflect2 v1.0.2 diff --git a/go.sum b/go.sum index 9b17d180..f59108a6 100644 --- a/go.sum +++ b/go.sum @@ -24,8 +24,8 @@ github.com/go-playground/validator/v10 v10.28.0 h1:Q7ibns33JjyW48gHkuFT91qX48KG0 github.com/go-playground/validator/v10 v10.28.0/go.mod h1:GoI6I1SjPBh9p7ykNE/yj3fFYbyDOpwMn5KXd+m2hUU= github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4= github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= -github.com/goccy/go-yaml v1.19.1 h1:3rG3+v8pkhRqoQ/88NYNMHYVGYztCOCIZ7UQhu7H+NE= -github.com/goccy/go-yaml v1.19.1/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA= +github.com/goccy/go-yaml v1.19.2 h1:PmFC1S6h8ljIz6gMRBopkjP1TVT7xuwrButHID66PoM= +github.com/goccy/go-yaml v1.19.2/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= From 6e3ac82fa71efda7d042b009b58215ca321f32ae Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 15 Feb 2026 10:57:06 +0800 Subject: [PATCH 06/70] chore(deps): bump github.com/quic-go/quic-go from 0.57.1 to 0.59.0 (#4532) Bumps [github.com/quic-go/quic-go](https://github.com/quic-go/quic-go) from 0.57.1 to 0.59.0. - [Release notes](https://github.com/quic-go/quic-go/releases) - [Commits](https://github.com/quic-go/quic-go/compare/v0.57.1...v0.59.0) --- updated-dependencies: - dependency-name: github.com/quic-go/quic-go dependency-version: 0.59.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 0496bc80..1bd4001f 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/mattn/go-isatty v0.0.20 github.com/modern-go/reflect2 v1.0.2 github.com/pelletier/go-toml/v2 v2.2.4 - github.com/quic-go/quic-go v0.57.1 + github.com/quic-go/quic-go v0.59.0 github.com/stretchr/testify v1.11.1 github.com/ugorji/go/codec v1.3.1 go.mongodb.org/mongo-driver v1.17.7 diff --git a/go.sum b/go.sum index f59108a6..6609e78d 100644 --- a/go.sum +++ b/go.sum @@ -52,8 +52,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/quic-go/qpack v0.6.0 h1:g7W+BMYynC1LbYLSqRt8PBg5Tgwxn214ZZR34VIOjz8= github.com/quic-go/qpack v0.6.0/go.mod h1:lUpLKChi8njB4ty2bFLX2x4gzDqXwUpaO1DP9qMDZII= -github.com/quic-go/quic-go v0.57.1 h1:25KAAR9QR8KZrCZRThWMKVAwGoiHIrNbT72ULHTuI10= -github.com/quic-go/quic-go v0.57.1/go.mod h1:ly4QBAjHA2VhdnxhojRsCUOeJwKYg+taDlos92xb1+s= +github.com/quic-go/quic-go v0.59.0 h1:OLJkp1Mlm/aS7dpKgTc6cnpynnD2Xg7C1pwL6vy/SAw= +github.com/quic-go/quic-go v0.59.0/go.mod h1:upnsH4Ju1YkqpLXC305eW3yDZ4NfnNbmQRCMWS58IKU= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -86,8 +86,6 @@ golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ= golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE= golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8= -golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE= -golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg= google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE= google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From bf52b077c812e1917d17944cb6f109ab4f462ae7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 15 Feb 2026 10:57:27 +0800 Subject: [PATCH 07/70] chore(deps): bump go.mongodb.org/mongo-driver from 1.17.7 to 1.17.9 (#4533) Bumps [go.mongodb.org/mongo-driver](https://github.com/mongodb/mongo-go-driver) from 1.17.7 to 1.17.9. - [Release notes](https://github.com/mongodb/mongo-go-driver/releases) - [Commits](https://github.com/mongodb/mongo-go-driver/compare/v1.17.7...v1.17.9) --- updated-dependencies: - dependency-name: go.mongodb.org/mongo-driver dependency-version: 1.17.9 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 1bd4001f..42774882 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/quic-go/quic-go v0.59.0 github.com/stretchr/testify v1.11.1 github.com/ugorji/go/codec v1.3.1 - go.mongodb.org/mongo-driver v1.17.7 + go.mongodb.org/mongo-driver v1.17.9 golang.org/x/net v0.49.0 google.golang.org/protobuf v1.36.10 ) diff --git a/go.sum b/go.sum index 6609e78d..51355809 100644 --- a/go.sum +++ b/go.sum @@ -71,8 +71,8 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go/codec v1.3.1 h1:waO7eEiFDwidsBN6agj1vJQ4AG7lh2yqXyOXqhgQuyY= github.com/ugorji/go/codec v1.3.1/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4= -go.mongodb.org/mongo-driver v1.17.7 h1:a9w+U3Vt67eYzcfq3k/OAv284/uUUkL0uP75VE5rCOU= -go.mongodb.org/mongo-driver v1.17.7/go.mod h1:Hy04i7O2kC4RS06ZrhPRqj/u4DTYkFDAAccj+rVKqgQ= +go.mongodb.org/mongo-driver v1.17.9 h1:IexDdCuuNJ3BHrELgBlyaH9p60JXAvdzWR128q+U5tU= +go.mongodb.org/mongo-driver v1.17.9/go.mod h1:LlOhpH5NUEfhxcAwG0UEkMqwYcc4JU18gtCdGudk/tQ= go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y= go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU= golang.org/x/arch v0.22.0 h1:c/Zle32i5ttqRXjdLyyHZESLD/bB90DCU1g9l/0YBDI= From f5c267d2f84ba8192dd9c4c67b0490abfa3dfe7a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 15 Feb 2026 10:58:17 +0800 Subject: [PATCH 08/70] chore(deps): bump aquasecurity/trivy-action in the actions group (#4534) Bumps the actions group with 1 update: [aquasecurity/trivy-action](https://github.com/aquasecurity/trivy-action). Updates `aquasecurity/trivy-action` from 0.33.1 to 0.34.0 - [Release notes](https://github.com/aquasecurity/trivy-action/releases) - [Commits](https://github.com/aquasecurity/trivy-action/compare/0.33.1...0.34.0) --- updated-dependencies: - dependency-name: aquasecurity/trivy-action dependency-version: 0.34.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: actions ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/trivy-scan.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/trivy-scan.yml b/.github/workflows/trivy-scan.yml index b86aed7f..ec8f55ad 100644 --- a/.github/workflows/trivy-scan.yml +++ b/.github/workflows/trivy-scan.yml @@ -27,7 +27,7 @@ jobs: fetch-depth: 0 - name: Run Trivy vulnerability scanner (source code) - uses: aquasecurity/trivy-action@0.33.1 + uses: aquasecurity/trivy-action@0.34.0 with: scan-type: 'fs' scan-ref: '.' @@ -44,7 +44,7 @@ jobs: sarif_file: 'trivy-results.sarif' - name: Run Trivy scanner (table output for logs) - uses: aquasecurity/trivy-action@0.33.1 + uses: aquasecurity/trivy-action@0.34.0 if: always() with: scan-type: 'fs' From 216a4a7c283bae102c4e365662566c895dbdad50 Mon Sep 17 00:00:00 2001 From: Amirhf Date: Tue, 17 Feb 2026 20:08:36 +0330 Subject: [PATCH 09/70] test(render): add comprehensive tests for MsgPack render (#4537) * test(render): add comprehensive tests for MsgPack render * test(render): make msgpack tests deterministic Decode the rendered msgpack output and assert values instead of comparing raw bytes (which can vary with map iteration order). Enable MsgpackHandle.RawToString so msgpack strings decode as Go strings. --------- Co-authored-by: AmirHossein Fallah --- render/render_msgpack_test.go | 58 ++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 11 deletions(-) diff --git a/render/render_msgpack_test.go b/render/render_msgpack_test.go index 579897cc..48b23870 100644 --- a/render/render_msgpack_test.go +++ b/render/render_msgpack_test.go @@ -7,7 +7,7 @@ package render import ( - "bytes" + "errors" "net/http/httptest" "testing" @@ -16,9 +16,6 @@ import ( "github.com/ugorji/go/codec" ) -// TODO unit tests -// test errors - func TestRenderMsgPack(t *testing.T) { w := httptest.NewRecorder() data := map[string]any{ @@ -32,13 +29,52 @@ func TestRenderMsgPack(t *testing.T) { require.NoError(t, err) - h := new(codec.MsgpackHandle) - assert.NotNil(t, h) - buf := bytes.NewBuffer([]byte{}) - assert.NotNil(t, buf) - err = codec.NewEncoder(buf, h).Encode(data) - + var decoded map[string]any + var mh codec.MsgpackHandle + mh.RawToString = true + err = codec.NewDecoderBytes(w.Body.Bytes(), &mh).Decode(&decoded) require.NoError(t, err) - assert.Equal(t, w.Body.String(), buf.String()) + assert.Equal(t, data, decoded) assert.Equal(t, "application/msgpack; charset=utf-8", w.Header().Get("Content-Type")) } + +func TestWriteMsgPack(t *testing.T) { + w := httptest.NewRecorder() + data := map[string]any{ + "foo": "bar", + "num": 42, + } + + err := WriteMsgPack(w, data) + require.NoError(t, err) + + assert.Equal(t, "application/msgpack; charset=utf-8", w.Header().Get("Content-Type")) + + var decoded map[string]any + var mh codec.MsgpackHandle + mh.RawToString = true + err = codec.NewDecoderBytes(w.Body.Bytes(), &mh).Decode(&decoded) + require.NoError(t, err) + assert.Len(t, decoded, 2) + assert.Equal(t, "bar", decoded["foo"]) + assert.EqualValues(t, 42, decoded["num"]) +} + +type failWriter struct { + *httptest.ResponseRecorder +} + +func (w *failWriter) Write(data []byte) (int, error) { + return 0, errors.New("write error") +} + +func TestRenderMsgPackError(t *testing.T) { + w := httptest.NewRecorder() + data := map[string]any{ + "foo": "bar", + } + + err := (MsgPack{data}).Render(&failWriter{w}) + require.Error(t, err) + assert.Contains(t, err.Error(), "write error") +} From 5f424ff6f6316511b7f1598ea6dba62ea1a62eb8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 18 Feb 2026 00:39:40 +0800 Subject: [PATCH 10/70] chore(deps): bump github.com/bytedance/sonic from 1.14.2 to 1.15.0 (#4539) Bumps [github.com/bytedance/sonic](https://github.com/bytedance/sonic) from 1.14.2 to 1.15.0. - [Release notes](https://github.com/bytedance/sonic/releases) - [Commits](https://github.com/bytedance/sonic/compare/v1.14.2...v1.15.0) --- updated-dependencies: - dependency-name: github.com/bytedance/sonic dependency-version: 1.15.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 42774882..87570423 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.24.0 toolchain go1.24.7 require ( - github.com/bytedance/sonic v1.14.2 + github.com/bytedance/sonic v1.15.0 github.com/gin-contrib/sse v1.1.0 github.com/go-playground/validator/v10 v10.28.0 github.com/goccy/go-json v0.10.5 @@ -26,7 +26,7 @@ require gopkg.in/yaml.v3 v3.0.1 // indirect require ( github.com/bytedance/gopkg v0.1.3 // indirect - github.com/bytedance/sonic/loader v0.4.0 // indirect + github.com/bytedance/sonic/loader v0.5.0 // indirect github.com/cloudwego/base64x v0.1.6 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/gabriel-vasile/mimetype v1.4.10 // indirect diff --git a/go.sum b/go.sum index 51355809..207dff51 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,9 @@ github.com/bytedance/gopkg v0.1.3 h1:TPBSwH8RsouGCBcMBktLt1AymVo2TVsBVCY4b6TnZ/M= github.com/bytedance/gopkg v0.1.3/go.mod h1:576VvJ+eJgyCzdjS+c4+77QF3p7ubbtiKARP3TxducM= -github.com/bytedance/sonic v1.14.2 h1:k1twIoe97C1DtYUo+fZQy865IuHia4PR5RPiuGPPIIE= -github.com/bytedance/sonic v1.14.2/go.mod h1:T80iDELeHiHKSc0C9tubFygiuXoGzrkjKzX2quAx980= -github.com/bytedance/sonic/loader v0.4.0 h1:olZ7lEqcxtZygCK9EKYKADnpQoYkRQxaeY2NYzevs+o= -github.com/bytedance/sonic/loader v0.4.0/go.mod h1:AR4NYCk5DdzZizZ5djGqQ92eEhCCcdf5x77udYiSJRo= +github.com/bytedance/sonic v1.15.0 h1:/PXeWFaR5ElNcVE84U0dOHjiMHQOwNIx3K4ymzh/uSE= +github.com/bytedance/sonic v1.15.0/go.mod h1:tFkWrPz0/CUCLEF4ri4UkHekCIcdnkqXw9VduqpJh0k= +github.com/bytedance/sonic/loader v0.5.0 h1:gXH3KVnatgY7loH5/TkeVyXPfESoqSBSBEiDd5VjlgE= +github.com/bytedance/sonic/loader v0.5.0/go.mod h1:AR4NYCk5DdzZizZ5djGqQ92eEhCCcdf5x77udYiSJRo= github.com/cloudwego/base64x v0.1.6 h1:t11wG9AECkCDk5fMSoxmufanudBtJ+/HemLstXDLI2M= github.com/cloudwego/base64x v0.1.6/go.mod h1:OFcloc187FXDaYHvrNIjxSe8ncn0OOM8gEHfghB2IPU= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= From 5260de6a83283abb87e827130accd495ad543cf3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 18 Feb 2026 00:40:02 +0800 Subject: [PATCH 11/70] chore(deps): bump golang.org/x/net from 0.49.0 to 0.50.0 (#4538) Bumps [golang.org/x/net](https://github.com/golang/net) from 0.49.0 to 0.50.0. - [Commits](https://github.com/golang/net/compare/v0.49.0...v0.50.0) --- updated-dependencies: - dependency-name: golang.org/x/net dependency-version: 0.50.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 87570423..19ff4752 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( github.com/stretchr/testify v1.11.1 github.com/ugorji/go/codec v1.3.1 go.mongodb.org/mongo-driver v1.17.9 - golang.org/x/net v0.49.0 + golang.org/x/net v0.50.0 google.golang.org/protobuf v1.36.10 ) @@ -41,7 +41,7 @@ require ( github.com/twitchyliquid64/golang-asm v0.15.1 // indirect go.uber.org/mock v0.6.0 // indirect golang.org/x/arch v0.22.0 // indirect - golang.org/x/crypto v0.47.0 // indirect - golang.org/x/sys v0.40.0 // indirect - golang.org/x/text v0.33.0 // indirect + golang.org/x/crypto v0.48.0 // indirect + golang.org/x/sys v0.41.0 // indirect + golang.org/x/text v0.34.0 // indirect ) diff --git a/go.sum b/go.sum index 207dff51..ef6d6eff 100644 --- a/go.sum +++ b/go.sum @@ -77,15 +77,15 @@ go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y= go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU= golang.org/x/arch v0.22.0 h1:c/Zle32i5ttqRXjdLyyHZESLD/bB90DCU1g9l/0YBDI= golang.org/x/arch v0.22.0/go.mod h1:dNHoOeKiyja7GTvF9NJS1l3Z2yntpQNzgrjh1cU103A= -golang.org/x/crypto v0.47.0 h1:V6e3FRj+n4dbpw86FJ8Fv7XVOql7TEwpHapKoMJ/GO8= -golang.org/x/crypto v0.47.0/go.mod h1:ff3Y9VzzKbwSSEzWqJsJVBnWmRwRSHt/6Op5n9bQc4A= -golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o= -golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8= +golang.org/x/crypto v0.48.0 h1:/VRzVqiRSggnhY7gNRxPauEQ5Drw9haKdM0jqfcCFts= +golang.org/x/crypto v0.48.0/go.mod h1:r0kV5h3qnFPlQnBSrULhlsRfryS2pmewsg+XfMgkVos= +golang.org/x/net v0.50.0 h1:ucWh9eiCGyDR3vtzso0WMQinm2Dnt8cFMuQa9K33J60= +golang.org/x/net v0.50.0/go.mod h1:UgoSli3F/pBgdJBHCTc+tp3gmrU4XswgGRgtnwWTfyM= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ= -golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= -golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE= -golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8= +golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k= +golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk= +golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA= google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE= google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From 00900fb3e1ea9dde33985a0e4f6afec793d5e786 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sat, 21 Feb 2026 22:32:32 +0800 Subject: [PATCH 12/70] ci: update CI workflows and standardize Trivy config quotes (#4531) - Update gin workflow to use v2.9 and add Go 1.26 to the matrix - Upgrade Trivy action to v0.34.0 in the scan workflow - Change all single quotes to double quotes in Trivy workflow configuration Signed-off-by: Bo-Yi Wu --- .github/workflows/gin.yml | 4 ++-- .github/workflows/trivy-scan.yml | 28 ++++++++++++++-------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/workflows/gin.yml b/.github/workflows/gin.yml index 8ece7f1d..df774eab 100644 --- a/.github/workflows/gin.yml +++ b/.github/workflows/gin.yml @@ -26,14 +26,14 @@ jobs: - name: Setup golangci-lint uses: golangci/golangci-lint-action@v9 with: - version: v2.6 + version: v2.9 args: --verbose test: needs: lint strategy: matrix: os: [ubuntu-latest, macos-latest] - go: ["1.24", "1.25"] + go: ["1.24", "1.25", "1.26"] test-tags: [ "", diff --git a/.github/workflows/trivy-scan.yml b/.github/workflows/trivy-scan.yml index ec8f55ad..57aceb76 100644 --- a/.github/workflows/trivy-scan.yml +++ b/.github/workflows/trivy-scan.yml @@ -9,7 +9,7 @@ on: - master schedule: # Run daily at 00:00 UTC - - cron: '0 0 * * *' + - cron: "0 0 * * *" workflow_dispatch: # Allow manual trigger permissions: @@ -29,28 +29,28 @@ jobs: - name: Run Trivy vulnerability scanner (source code) uses: aquasecurity/trivy-action@0.34.0 with: - scan-type: 'fs' - scan-ref: '.' - scanners: 'vuln,secret,misconfig' - format: 'sarif' - output: 'trivy-results.sarif' - severity: 'CRITICAL,HIGH,MEDIUM' + scan-type: "fs" + scan-ref: "." + scanners: "vuln,secret,misconfig" + format: "sarif" + output: "trivy-results.sarif" + severity: "CRITICAL,HIGH,MEDIUM" ignore-unfixed: true - name: Upload Trivy results to GitHub Security tab uses: github/codeql-action/upload-sarif@v4 if: always() with: - sarif_file: 'trivy-results.sarif' + sarif_file: "trivy-results.sarif" - name: Run Trivy scanner (table output for logs) uses: aquasecurity/trivy-action@0.34.0 if: always() with: - scan-type: 'fs' - scan-ref: '.' - scanners: 'vuln,secret,misconfig' - format: 'table' - severity: 'CRITICAL,HIGH,MEDIUM' + scan-type: "fs" + scan-ref: "." + scanners: "vuln,secret,misconfig" + format: "table" + severity: "CRITICAL,HIGH,MEDIUM" ignore-unfixed: true - exit-code: '1' + exit-code: "1" From 0c219e7902e88b27be1736d46efb241e4482b30f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 21 Feb 2026 22:33:30 +0800 Subject: [PATCH 13/70] chore(deps): bump aquasecurity/trivy-action in the actions group (#4544) Bumps the actions group with 1 update: [aquasecurity/trivy-action](https://github.com/aquasecurity/trivy-action). Updates `aquasecurity/trivy-action` from 0.34.0 to 0.34.1 - [Release notes](https://github.com/aquasecurity/trivy-action/releases) - [Commits](https://github.com/aquasecurity/trivy-action/compare/0.34.0...0.34.1) --- updated-dependencies: - dependency-name: aquasecurity/trivy-action dependency-version: 0.34.1 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: actions ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/trivy-scan.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/trivy-scan.yml b/.github/workflows/trivy-scan.yml index 57aceb76..a4c62bf4 100644 --- a/.github/workflows/trivy-scan.yml +++ b/.github/workflows/trivy-scan.yml @@ -27,7 +27,7 @@ jobs: fetch-depth: 0 - name: Run Trivy vulnerability scanner (source code) - uses: aquasecurity/trivy-action@0.34.0 + uses: aquasecurity/trivy-action@0.34.1 with: scan-type: "fs" scan-ref: "." @@ -44,7 +44,7 @@ jobs: sarif_file: "trivy-results.sarif" - name: Run Trivy scanner (table output for logs) - uses: aquasecurity/trivy-action@0.34.0 + uses: aquasecurity/trivy-action@0.34.1 if: always() with: scan-type: "fs" From 81dba468722f41347ed74ee66e9c1781d72f68a5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 21 Feb 2026 22:39:56 +0800 Subject: [PATCH 14/70] chore(deps): bump github.com/go-playground/validator/v10 (#4509) Bumps [github.com/go-playground/validator/v10](https://github.com/go-playground/validator) from 10.28.0 to 10.30.1. - [Release notes](https://github.com/go-playground/validator/releases) - [Commits](https://github.com/go-playground/validator/compare/v10.28.0...v10.30.1) --- updated-dependencies: - dependency-name: github.com/go-playground/validator/v10 dependency-version: 10.30.1 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 19ff4752..459e9cdc 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ toolchain go1.24.7 require ( github.com/bytedance/sonic v1.15.0 github.com/gin-contrib/sse v1.1.0 - github.com/go-playground/validator/v10 v10.28.0 + github.com/go-playground/validator/v10 v10.30.1 github.com/goccy/go-json v0.10.5 github.com/goccy/go-yaml v1.19.2 github.com/json-iterator/go v1.1.12 @@ -29,7 +29,7 @@ require ( github.com/bytedance/sonic/loader v0.5.0 // indirect github.com/cloudwego/base64x v0.1.6 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/gabriel-vasile/mimetype v1.4.10 // indirect + github.com/gabriel-vasile/mimetype v1.4.12 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/klauspost/cpuid/v2 v2.3.0 // indirect diff --git a/go.sum b/go.sum index ef6d6eff..624997b8 100644 --- a/go.sum +++ b/go.sum @@ -10,8 +10,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/gabriel-vasile/mimetype v1.4.10 h1:zyueNbySn/z8mJZHLt6IPw0KoZsiQNszIpU+bX4+ZK0= -github.com/gabriel-vasile/mimetype v1.4.10/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s= +github.com/gabriel-vasile/mimetype v1.4.12 h1:e9hWvmLYvtp846tLHam2o++qitpguFiYCKbn0w9jyqw= +github.com/gabriel-vasile/mimetype v1.4.12/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s= github.com/gin-contrib/sse v1.1.0 h1:n0w2GMuUpWDVp7qSpvze6fAu9iRxJY4Hmj6AmBOU05w= github.com/gin-contrib/sse v1.1.0/go.mod h1:hxRZ5gVpWMT7Z0B0gSNYqqsSCNIJMjzvm6fqCz9vjwM= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= @@ -20,8 +20,8 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.28.0 h1:Q7ibns33JjyW48gHkuFT91qX48KG0ktULL6FgHdG688= -github.com/go-playground/validator/v10 v10.28.0/go.mod h1:GoI6I1SjPBh9p7ykNE/yj3fFYbyDOpwMn5KXd+m2hUU= +github.com/go-playground/validator/v10 v10.30.1 h1:f3zDSN/zOma+w6+1Wswgd9fLkdwy06ntQJp0BBvFG0w= +github.com/go-playground/validator/v10 v10.30.1/go.mod h1:oSuBIQzuJxL//3MelwSLD5hc2Tu889bF0Idm9Dg26cM= github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4= github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= github.com/goccy/go-yaml v1.19.2 h1:PmFC1S6h8ljIz6gMRBopkjP1TVT7xuwrButHID66PoM= From 1b414bd54e467cb7278de8877401af07f185edb0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 27 Feb 2026 23:18:28 +0800 Subject: [PATCH 15/70] chore(deps): bump goreleaser/goreleaser-action in the actions group (#4546) Bumps the actions group with 1 update: [goreleaser/goreleaser-action](https://github.com/goreleaser/goreleaser-action). Updates `goreleaser/goreleaser-action` from 6 to 7 - [Release notes](https://github.com/goreleaser/goreleaser-action/releases) - [Commits](https://github.com/goreleaser/goreleaser-action/compare/v6...v7) --- updated-dependencies: - dependency-name: goreleaser/goreleaser-action dependency-version: '7' dependency-type: direct:production update-type: version-update:semver-major dependency-group: actions ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/goreleaser.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml index 0098b952..ea933e7e 100644 --- a/.github/workflows/goreleaser.yml +++ b/.github/workflows/goreleaser.yml @@ -21,7 +21,7 @@ jobs: with: go-version: "^1" - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v6 + uses: goreleaser/goreleaser-action@v7 with: # either 'goreleaser' (default) or 'goreleaser-pro' distribution: goreleaser From ba093d19477b896ac89a7fc3246af23d290b8e26 Mon Sep 17 00:00:00 2001 From: Bob Du Date: Fri, 27 Feb 2026 23:20:01 +0800 Subject: [PATCH 16/70] chore(binding): upgrade bson dependency to mongo-driver v2 (#4549) Signed-off-by: Bob Du --- binding/binding_test.go | 2 +- binding/bson.go | 2 +- context_test.go | 2 +- go.mod | 2 +- go.sum | 4 ++-- render/bson.go | 2 +- render/render_test.go | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/binding/binding_test.go b/binding/binding_test.go index a9f8b9e3..f90488cd 100644 --- a/binding/binding_test.go +++ b/binding/binding_test.go @@ -21,7 +21,7 @@ import ( "github.com/gin-gonic/gin/testdata/protoexample" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/v2/bson" "google.golang.org/protobuf/proto" ) diff --git a/binding/bson.go b/binding/bson.go index 4a698247..464890f0 100644 --- a/binding/bson.go +++ b/binding/bson.go @@ -8,7 +8,7 @@ import ( "io" "net/http" - "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/v2/bson" ) type bsonBinding struct{} diff --git a/context_test.go b/context_test.go index 41694585..41ec7bd5 100644 --- a/context_test.go +++ b/context_test.go @@ -32,7 +32,7 @@ import ( testdata "github.com/gin-gonic/gin/testdata/protoexample" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/v2/bson" "google.golang.org/protobuf/proto" ) diff --git a/go.mod b/go.mod index 459e9cdc..0f278049 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/quic-go/quic-go v0.59.0 github.com/stretchr/testify v1.11.1 github.com/ugorji/go/codec v1.3.1 - go.mongodb.org/mongo-driver v1.17.9 + go.mongodb.org/mongo-driver/v2 v2.5.0 golang.org/x/net v0.50.0 google.golang.org/protobuf v1.36.10 ) diff --git a/go.sum b/go.sum index 624997b8..71c07795 100644 --- a/go.sum +++ b/go.sum @@ -71,8 +71,8 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go/codec v1.3.1 h1:waO7eEiFDwidsBN6agj1vJQ4AG7lh2yqXyOXqhgQuyY= github.com/ugorji/go/codec v1.3.1/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4= -go.mongodb.org/mongo-driver v1.17.9 h1:IexDdCuuNJ3BHrELgBlyaH9p60JXAvdzWR128q+U5tU= -go.mongodb.org/mongo-driver v1.17.9/go.mod h1:LlOhpH5NUEfhxcAwG0UEkMqwYcc4JU18gtCdGudk/tQ= +go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE= +go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0= go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y= go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU= golang.org/x/arch v0.22.0 h1:c/Zle32i5ttqRXjdLyyHZESLD/bB90DCU1g9l/0YBDI= diff --git a/render/bson.go b/render/bson.go index 7332b8b2..07f02333 100644 --- a/render/bson.go +++ b/render/bson.go @@ -7,7 +7,7 @@ package render import ( "net/http" - "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/v2/bson" ) // BSON contains the given interface object. diff --git a/render/render_test.go b/render/render_test.go index 7213e48f..40e7e7be 100644 --- a/render/render_test.go +++ b/render/render_test.go @@ -19,7 +19,7 @@ import ( testdata "github.com/gin-gonic/gin/testdata/protoexample" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/v2/bson" "google.golang.org/protobuf/proto" ) From db309081bc5c137b2aa15701ef53f7f19788da25 Mon Sep 17 00:00:00 2001 From: Jacob McSwain Date: Fri, 27 Feb 2026 09:33:46 -0600 Subject: [PATCH 17/70] chore(logger): allow skipping query string output (#4547) This is useful for APIs that might have sensitive information in the query string, such as API keys. This patch does not change the default behavior of the code unless the new `SkipQueryString` config option is passed in. The "skip" term is a bit of a misnomer here, as this doesn't actually skip that log, but modifies the output. I'm open to suggestions for a more appropriate name. Co-authored-by: Bo-Yi Wu --- docs/doc.md | 15 +++++++++++++++ logger.go | 7 ++++++- logger_test.go | 14 ++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/docs/doc.md b/docs/doc.md index 449c8d02..7201df5c 100644 --- a/docs/doc.md +++ b/docs/doc.md @@ -22,6 +22,7 @@ - [How to write log file](#how-to-write-log-file) - [Custom Log Format](#custom-log-format) - [Controlling Log output coloring](#controlling-log-output-coloring) + - [Avoid logging query strings](#avoid-loging-query-strings) - [Model binding and validation](#model-binding-and-validation) - [Custom Validators](#custom-validators) - [Only Bind Query String](#only-bind-query-string) @@ -592,6 +593,20 @@ func main() { } ``` +### Avoid logging query strings + +```go +func main() { + router := gin.New() + + // SkipQueryString indicates that the logger should not log the query string. + // For example, /path?q=1 will be logged as /path + loggerConfig := gin.LoggerConfig{SkipQueryString: true} + + router.Use(gin.LoggerWithConfig(loggerConfig)) +} +``` + ### Model binding and validation To bind a request body into a type, use model binding. We currently support binding of JSON, XML, YAML, TOML and standard form values (foo=bar&boo=baz). diff --git a/logger.go b/logger.go index 6441f7ea..cf92553a 100644 --- a/logger.go +++ b/logger.go @@ -48,6 +48,11 @@ type LoggerConfig struct { // Optional. SkipPaths []string + // SkipQueryString indicates that query strings should not be written + // for cases such as when API keys are passed via query strings. + // Optional. Default value is false. + SkipQueryString bool + // Skip is a Skipper that indicates which logs should not be written. // Optional. Skip Skipper @@ -298,7 +303,7 @@ func LoggerWithConfig(conf LoggerConfig) HandlerFunc { param.BodySize = c.Writer.Size() - if raw != "" { + if raw != "" && !conf.SkipQueryString { path = path + "?" + raw } diff --git a/logger_test.go b/logger_test.go index 53d0df95..8099a894 100644 --- a/logger_test.go +++ b/logger_test.go @@ -471,3 +471,17 @@ func TestForceConsoleColor(t *testing.T) { // reset console color mode. consoleColorMode = autoColor } + +func TestLoggerWithConfigSkipQueryString(t *testing.T) { + buffer := new(strings.Builder) + router := New() + router.Use(LoggerWithConfig(LoggerConfig{ + Output: buffer, + SkipQueryString: true, + })) + router.GET("/logged", func(c *Context) { c.Status(http.StatusOK) }) + + PerformRequest(router, "GET", "/logged?a=21") + assert.Contains(t, buffer.String(), "200") + assert.NotContains(t, buffer.String(), "a=21") +} From 5c00df8afadd06cc5be530dde00fe6d9fa4a2e4a Mon Sep 17 00:00:00 2001 From: Denis Galeev <11516397+dengaleev@users.noreply.github.com> Date: Sat, 28 Feb 2026 09:07:31 +0700 Subject: [PATCH 18/70] fix(render): write content length in Data.Render (#4206) * init test * fix test * fix assert.EqualValues usage --------- Co-authored-by: Bo-Yi Wu --- render/data.go | 8 +++++++- render/render_test.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/render/data.go b/render/data.go index a653ea30..2c0ad5e3 100644 --- a/render/data.go +++ b/render/data.go @@ -4,7 +4,10 @@ package render -import "net/http" +import ( + "net/http" + "strconv" +) // Data contains ContentType and bytes data. type Data struct { @@ -15,6 +18,9 @@ type Data struct { // Render (Data) writes data with custom ContentType. func (r Data) Render(w http.ResponseWriter) (err error) { r.WriteContentType(w) + if len(r.Data) > 0 { + w.Header().Set("Content-Length", strconv.Itoa(len(r.Data))) + } _, err = w.Write(r.Data) return } diff --git a/render/render_test.go b/render/render_test.go index 40e7e7be..9c3019eb 100644 --- a/render/render_test.go +++ b/render/render_test.go @@ -8,6 +8,7 @@ import ( "encoding/xml" "errors" "html/template" + "io" "net" "net/http" "net/http/httptest" @@ -453,6 +454,36 @@ func TestRenderData(t *testing.T) { require.NoError(t, err) assert.Equal(t, "#!PNG some raw data", w.Body.String()) assert.Equal(t, "image/png", w.Header().Get("Content-Type")) + assert.Equal(t, "19", w.Header().Get("Content-Length")) +} + +func TestRenderDataContentLength(t *testing.T) { + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + size, err := strconv.Atoi(r.URL.Query().Get("size")) + assert.NoError(t, err) + + data := Data{ + ContentType: "application/octet-stream", + Data: make([]byte, size), + } + assert.NoError(t, data.Render(w)) + })) + t.Cleanup(srv.Close) + + for _, size := range []int{0, 1, 100, 100_000} { + t.Run(strconv.Itoa(size), func(t *testing.T) { + resp, err := http.Get(srv.URL + "?size=" + strconv.Itoa(size)) + require.NoError(t, err) + defer resp.Body.Close() + + assert.Equal(t, "application/octet-stream", resp.Header.Get("Content-Type")) + assert.Equal(t, strconv.Itoa(size), resp.Header.Get("Content-Length")) + + actual, err := io.Copy(io.Discard, resp.Body) + require.NoError(t, err) + assert.EqualValues(t, size, actual) + }) + } } func TestRenderString(t *testing.T) { From 6f1d5fe3cdb171a08928c3c9dd3fbcfc9ee1b521 Mon Sep 17 00:00:00 2001 From: Amirhf Date: Sat, 28 Feb 2026 05:41:57 +0330 Subject: [PATCH 19/70] test(render): add comprehensive error handling tests (#4541) * test(render): add comprehensive error handling tests Add error case tests for XML, Data, BSON, and HTML renderers to improve test coverage and ensure proper error handling: - TestRenderXMLError: validates XML marshal error handling for unsupported types - TestRenderDataError: validates Data write error handling - TestRenderBSONError: validates BSON marshal error handling for unsupported types - TestRenderBSONWriteError: validates BSON write error handling - TestRenderHTMLTemplateError: validates HTML template execution error with invalid field access - TestRenderHTMLTemplateExecuteError: validates HTML template execution error with invalid nested field All tests pass and maintain 100% coverage for the render package. * test(render): improve robustness of error handling tests based on PR feedback --------- Co-authored-by: Bo-Yi Wu Co-authored-by: AmirHossein Fallah --- render/render_test.go | 146 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 126 insertions(+), 20 deletions(-) diff --git a/render/render_test.go b/render/render_test.go index 9c3019eb..b48ab3d3 100644 --- a/render/render_test.go +++ b/render/render_test.go @@ -16,7 +16,6 @@ import ( "strings" "testing" - "github.com/gin-gonic/gin/codec/json" testdata "github.com/gin-gonic/gin/testdata/protoexample" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -24,9 +23,6 @@ import ( "google.golang.org/protobuf/proto" ) -// TODO unit tests -// test errors - func TestRenderJSON(t *testing.T) { w := httptest.NewRecorder() data := map[string]any{ @@ -141,19 +137,44 @@ func TestRenderJsonpJSON(t *testing.T) { } type errorWriter struct { - bufString string + bufString string + ErrThreshold int // 1-based threshold. If 1, errors on the 1st Write call. + writeCount int *httptest.ResponseRecorder } var _ http.ResponseWriter = (*errorWriter)(nil) +func (w *errorWriter) Header() http.Header { + if w.ResponseRecorder == nil { + w.ResponseRecorder = httptest.NewRecorder() + } + return w.ResponseRecorder.Header() +} + +func (w *errorWriter) WriteHeader(statusCode int) { + if w.ResponseRecorder == nil { + w.ResponseRecorder = httptest.NewRecorder() + } + w.ResponseRecorder.WriteHeader(statusCode) +} + func (w *errorWriter) Write(buf []byte) (int, error) { - if string(buf) == w.bufString { - return 0, errors.New(`write "` + w.bufString + `" error`) + w.writeCount++ + if (w.bufString != "" && string(buf) == w.bufString) || (w.ErrThreshold > 0 && w.writeCount >= w.ErrThreshold) { + return 0, errors.New(`write error`) + } + if w.ResponseRecorder == nil { + w.ResponseRecorder = httptest.NewRecorder() } return w.ResponseRecorder.Write(buf) } +func (w *errorWriter) reset() { + w.writeCount = 0 + w.ResponseRecorder = httptest.NewRecorder() +} + func TestRenderJsonpJSONError(t *testing.T) { ew := &errorWriter{ ResponseRecorder: httptest.NewRecorder(), @@ -166,23 +187,33 @@ func TestRenderJsonpJSONError(t *testing.T) { }, } - cb := template.JSEscapeString(jsonpJSON.Callback) - ew.bufString = cb - err := jsonpJSON.Render(ew) // error was returned while writing callback - assert.Equal(t, `write "`+cb+`" error`, err.Error()) + // error was returned while writing callback + ew.reset() + ew.ErrThreshold = 1 + err := jsonpJSON.Render(ew) + require.Error(t, err) + assert.Equal(t, "write error", err.Error()) - ew.bufString = `(` + // error was returned while writing "(" + ew.reset() + ew.ErrThreshold = 2 err = jsonpJSON.Render(ew) - assert.Equal(t, `write "`+`(`+`" error`, err.Error()) + require.Error(t, err) + assert.Equal(t, "write error", err.Error()) - data, _ := json.API.Marshal(jsonpJSON.Data) // error was returned while writing data - ew.bufString = string(data) + // error was returned while writing data + ew.reset() + ew.ErrThreshold = 3 err = jsonpJSON.Render(ew) - assert.Equal(t, `write "`+string(data)+`" error`, err.Error()) + require.Error(t, err) + assert.Equal(t, "write error", err.Error()) - ew.bufString = `);` + // error was returned while writing ");" + ew.reset() + ew.ErrThreshold = 4 err = jsonpJSON.Render(ew) - assert.Equal(t, `write "`+`);`+`" error`, err.Error()) + require.Error(t, err) + assert.Equal(t, "write error", err.Error()) } func TestRenderJsonpJSONError2(t *testing.T) { @@ -386,6 +417,30 @@ func TestRenderBSON(t *testing.T) { assert.Equal(t, "application/bson", w.Header().Get("Content-Type")) } +func TestRenderBSONError(t *testing.T) { + w := httptest.NewRecorder() + data := make(chan int) + + err := (BSON{data}).Render(w) + require.Error(t, err) +} + +func TestRenderBSONWriteError(t *testing.T) { + type testStruct struct { + Value string + } + data := &testStruct{Value: "test"} + + ew := &errorWriter{ + ErrThreshold: 1, + ResponseRecorder: httptest.NewRecorder(), + } + + err := (BSON{data}).Render(ew) + require.Error(t, err) + assert.Equal(t, "write error", err.Error()) +} + func TestRenderXML(t *testing.T) { w := httptest.NewRecorder() data := xmlmap{ @@ -402,6 +457,15 @@ func TestRenderXML(t *testing.T) { assert.Equal(t, "application/xml; charset=utf-8", w.Header().Get("Content-Type")) } +func TestRenderXMLError(t *testing.T) { + w := httptest.NewRecorder() + data := make(chan int) + + err := (XML{data}).Render(w) + require.Error(t, err) + assert.Contains(t, err.Error(), "xml: unsupported type: chan int") +} + func TestRenderRedirect(t *testing.T) { req, err := http.NewRequest(http.MethodGet, "/test-redirect", nil) require.NoError(t, err) @@ -486,6 +550,22 @@ func TestRenderDataContentLength(t *testing.T) { } } +func TestRenderDataError(t *testing.T) { + ew := &errorWriter{ + ErrThreshold: 1, + ResponseRecorder: httptest.NewRecorder(), + } + data := []byte("#!PNG some raw data") + + err := (Data{ + ContentType: "image/png", + Data: data, + }).Render(ew) + + require.Error(t, err) + assert.Equal(t, "write error", err.Error()) +} + func TestRenderString(t *testing.T) { w := httptest.NewRecorder() @@ -625,6 +705,32 @@ func TestRenderHTMLDebugPanics(t *testing.T) { assert.Panics(t, func() { htmlRender.Instance("", nil) }) } +func TestRenderHTMLTemplateError(t *testing.T) { + w := httptest.NewRecorder() + templ := template.Must(template.New("t").Parse(`Hello {{if .name}}{{.name.DoesNotExist}}{{end}}`)) + + htmlRender := HTMLProduction{Template: templ} + instance := htmlRender.Instance("t", map[string]any{ + "name": "alexandernyquist", + }) + + err := instance.Render(w) + require.Error(t, err) +} + +func TestRenderHTMLTemplateExecuteError(t *testing.T) { + w := httptest.NewRecorder() + templ := template.Must(template.New("t").Parse(`Hello {{.name.invalid}}`)) + + htmlRender := HTMLProduction{Template: templ} + instance := htmlRender.Instance("t", map[string]any{ + "name": "alexandernyquist", + }) + + err := instance.Render(w) + require.Error(t, err) +} + func TestRenderReader(t *testing.T) { w := httptest.NewRecorder() @@ -676,10 +782,10 @@ func TestRenderWriteError(t *testing.T) { prefix := "my-prefix:" r := SecureJSON{Data: data, Prefix: prefix} ew := &errorWriter{ - bufString: prefix, + ErrThreshold: 1, ResponseRecorder: httptest.NewRecorder(), } err := r.Render(ew) require.Error(t, err) - assert.Equal(t, `write "my-prefix:" error`, err.Error()) + assert.Equal(t, "write error", err.Error()) } From fb2583442c4d9bccb75e6d26f1aa6e7c01950db6 Mon Sep 17 00:00:00 2001 From: Mehrdad Banikian <80095851+mehrdadbn9@users.noreply.github.com> Date: Sat, 28 Feb 2026 05:43:11 +0330 Subject: [PATCH 20/70] test(context): use http.StatusContinue constant instead of magic number 100 (#4542) * refactor(context): use http.StatusContinue constant instead of magic number 100 Replace magic number 100 with http.StatusContinue constant for better code clarity and maintainability in bodyAllowedForStatus function. Also fix typo in logger_test.go: colorForLantency -> colorForLatency Fixes #4489 * test: improve coverage to meet 99% threshold - Add TestContextGetRawDataNilBody to cover nil body error case - Add SameSiteDefaultMode test case in SetCookieData - Add 400ms latency test case for LatencyColor - Add TestMarshalXMLforHSuccess for successful XML marshaling Coverage improved from 99.1% to 99.2% * fix: use require for error assertions (testifylint) --- context.go | 1 + context_test.go | 29 +++++++++++++++++++++++++++++ logger_test.go | 17 +++++++++-------- utils_test.go | 12 ++++++++++++ 4 files changed, 51 insertions(+), 8 deletions(-) diff --git a/context.go b/context.go index a00d1e55..92fb3704 100644 --- a/context.go +++ b/context.go @@ -1056,6 +1056,7 @@ func (c *Context) requestHeader(key string) string { /************************************/ // bodyAllowedForStatus is a copy of http.bodyAllowedForStatus non-exported function. +// Uses http.StatusContinue constant for better code clarity. func bodyAllowedForStatus(status int) bool { switch { case status >= http.StatusContinue && status < http.StatusOK: diff --git a/context_test.go b/context_test.go index 41ec7bd5..44db7475 100644 --- a/context_test.go +++ b/context_test.go @@ -1031,6 +1031,7 @@ func TestContextGetCookie(t *testing.T) { } func TestContextBodyAllowedForStatus(t *testing.T) { + assert.False(t, bodyAllowedForStatus(http.StatusContinue)) assert.False(t, bodyAllowedForStatus(http.StatusProcessing)) assert.False(t, bodyAllowedForStatus(http.StatusNoContent)) assert.False(t, bodyAllowedForStatus(http.StatusNotModified)) @@ -2947,6 +2948,16 @@ func TestContextGetRawData(t *testing.T) { assert.Equal(t, "Fetch binary post data", string(data)) } +func TestContextGetRawDataNilBody(t *testing.T) { + c, _ := CreateTestContext(httptest.NewRecorder()) + c.Request, _ = http.NewRequest(http.MethodPost, "/", nil) + + data, err := c.GetRawData() + assert.Nil(t, data) + require.Error(t, err) + assert.Equal(t, "cannot read nil body", err.Error()) +} + func TestContextRenderDataFromReader(t *testing.T) { w := httptest.NewRecorder() c, _ := CreateTestContext(w) @@ -3535,6 +3546,24 @@ func TestContextSetCookieData(t *testing.T) { setCookie := c.Writer.Header().Get("Set-Cookie") assert.Contains(t, setCookie, "SameSite=None") }) + + // Test that SameSiteDefaultMode inherits from context's sameSite + t.Run("SameSiteDefaultMode inherits context sameSite", func(t *testing.T) { + c, _ := CreateTestContext(httptest.NewRecorder()) + c.SetSameSite(http.SameSiteStrictMode) + cookie := &http.Cookie{ + Name: "user", + Value: "gin", + Path: "/", + Domain: "localhost", + Secure: true, + HttpOnly: true, + SameSite: http.SameSiteDefaultMode, + } + c.SetCookieData(cookie) + setCookie := c.Writer.Header().Get("Set-Cookie") + assert.Contains(t, setCookie, "SameSite=Strict") + }) } func TestGetMapFromFormData(t *testing.T) { diff --git a/logger_test.go b/logger_test.go index 8099a894..395d97e6 100644 --- a/logger_test.go +++ b/logger_test.go @@ -318,20 +318,21 @@ func TestColorForStatus(t *testing.T) { } func TestColorForLatency(t *testing.T) { - colorForLantency := func(latency time.Duration) string { + colorForLatency := func(latency time.Duration) string { p := LogFormatterParams{ Latency: latency, } return p.LatencyColor() } - assert.Equal(t, white, colorForLantency(time.Duration(0)), "0 should be white") - assert.Equal(t, white, colorForLantency(time.Millisecond*20), "20ms should be white") - assert.Equal(t, green, colorForLantency(time.Millisecond*150), "150ms should be green") - assert.Equal(t, cyan, colorForLantency(time.Millisecond*250), "250ms should be cyan") - assert.Equal(t, yellow, colorForLantency(time.Millisecond*600), "600ms should be yellow") - assert.Equal(t, magenta, colorForLantency(time.Millisecond*1500), "1.5s should be magenta") - assert.Equal(t, red, colorForLantency(time.Second*3), "other things should be red") + assert.Equal(t, white, colorForLatency(time.Duration(0)), "0 should be white") + assert.Equal(t, white, colorForLatency(time.Millisecond*20), "20ms should be white") + assert.Equal(t, green, colorForLatency(time.Millisecond*150), "150ms should be green") + assert.Equal(t, cyan, colorForLatency(time.Millisecond*250), "250ms should be cyan") + assert.Equal(t, blue, colorForLatency(time.Millisecond*400), "400ms should be blue") + assert.Equal(t, yellow, colorForLatency(time.Millisecond*600), "600ms should be yellow") + assert.Equal(t, magenta, colorForLatency(time.Millisecond*1500), "1.5s should be magenta") + assert.Equal(t, red, colorForLatency(time.Second*3), "other things should be red") } func TestResetColor(t *testing.T) { diff --git a/utils_test.go b/utils_test.go index 893ebc88..e1f2c332 100644 --- a/utils_test.go +++ b/utils_test.go @@ -13,6 +13,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func init() { @@ -145,6 +146,17 @@ func TestMarshalXMLforH(t *testing.T) { assert.Error(t, e) } +func TestMarshalXMLforHSuccess(t *testing.T) { + h := H{ + "key1": "value1", + "key2": 123, + } + data, err := xml.Marshal(h) + require.NoError(t, err) + assert.Contains(t, string(data), "value1") + assert.Contains(t, string(data), "123") +} + func TestIsASCII(t *testing.T) { assert.True(t, isASCII("test")) assert.False(t, isASCII("🧡💛💚💙💜")) From 472d086af2acd924cb4b9d7be0525f7d790f69bc Mon Sep 17 00:00:00 2001 From: Varun Chawla <34209028+veeceey@users.noreply.github.com> Date: Fri, 27 Feb 2026 19:15:27 -0800 Subject: [PATCH 21/70] fix(tree): panic in findCaseInsensitivePathRec with RedirectFixedPath (#4535) * fix(tree): panic in findCaseInsensitivePathRec with RedirectFixedPath enabled When RedirectFixedPath is enabled and a request doesn't match any route, findCaseInsensitivePathRec panics with "invalid node type". This happens because it accesses children[0] to find the wildcard child, but addChild() keeps the wildcard child at the end of the array (not the beginning). When a node has both static and wildcard children, children[0] is a static node, so the switch on nType falls through to the default panic case. The fix mirrors what getValue() already does correctly (line 483): use children[len(children)-1] to access the wildcard child. Fixes #2959 * Address review feedback: improve test assertions and prefer static routes in case-insensitive lookup - Assert found=false for non-matching paths instead of only checking for panics - Fix expected casing for case-insensitive static route match (/PREFIX/XXX -> /prefix/xxx) - Update findCaseInsensitivePathRec to try static children before falling back to wildcard child, ensuring static routes win over param routes in case-insensitive matching --------- Co-authored-by: Bo-Yi Wu --- tree.go | 67 ++++++++++++++++++++++++++++++++++++- tree_test.go | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 159 insertions(+), 1 deletion(-) diff --git a/tree.go b/tree.go index 3ac0a3b1..580abbaf 100644 --- a/tree.go +++ b/tree.go @@ -818,7 +818,72 @@ walk: // Outer loop for walking the tree return nil } - n = n.children[0] + // When wildChild is true, try static children first (via indices) + // before falling back to the wildcard child. This ensures that + // case-insensitive lookups prefer static routes over param routes + // (e.g., /PREFIX/XXX should resolve to /prefix/xxx, not match :id). + if len(n.indices) > 0 { + rb = shiftNRuneBytes(rb, npLen) + + if rb[0] != 0 { + idxc := rb[0] + for i, c := range []byte(n.indices) { + if c == idxc { + if out := n.children[i].findCaseInsensitivePathRec( + path, ciPath, rb, fixTrailingSlash, + ); out != nil { + return out + } + break + } + } + } else { + var rv rune + var off int + for max_ := min(npLen, 3); off < max_; off++ { + if i := npLen - off; utf8.RuneStart(oldPath[i]) { + rv, _ = utf8.DecodeRuneInString(oldPath[i:]) + break + } + } + + lo := unicode.ToLower(rv) + utf8.EncodeRune(rb[:], lo) + rb = shiftNRuneBytes(rb, off) + + idxc := rb[0] + for i, c := range []byte(n.indices) { + if c == idxc { + if out := n.children[i].findCaseInsensitivePathRec( + path, ciPath, rb, fixTrailingSlash, + ); out != nil { + return out + } + break + } + } + + if up := unicode.ToUpper(rv); up != lo { + utf8.EncodeRune(rb[:], up) + rb = shiftNRuneBytes(rb, off) + + idxc := rb[0] + for i, c := range []byte(n.indices) { + if c == idxc { + if out := n.children[i].findCaseInsensitivePathRec( + path, ciPath, rb, fixTrailingSlash, + ); out != nil { + return out + } + break + } + } + } + } + } + + // Fall back to wildcard child, which is always at the end of the array + n = n.children[len(n.children)-1] switch n.nType { case param: // Find param end (either '/' or path end) diff --git a/tree_test.go b/tree_test.go index b580007d..23339af4 100644 --- a/tree_test.go +++ b/tree_test.go @@ -1018,3 +1018,96 @@ func TestWildcardInvalidSlash(t *testing.T) { } } } + +func TestTreeFindCaseInsensitivePathWithMultipleChildrenAndWildcard(t *testing.T) { + tree := &node{} + + // Setup routes that create a node with both static children and a wildcard child. + // This configuration previously caused a panic ("invalid node type") in + // findCaseInsensitivePathRec because it accessed children[0] instead of the + // wildcard child (which is always at the end of the children array). + // See: https://github.com/gin-gonic/gin/issues/2959 + routes := [...]string{ + "/aa/aa", + "/:bb/aa", + } + + for _, route := range routes { + recv := catchPanic(func() { + tree.addRoute(route, fakeHandler(route)) + }) + if recv != nil { + t.Fatalf("panic inserting route '%s': %v", route, recv) + } + } + + // These lookups previously panicked with "invalid node type" because + // findCaseInsensitivePathRec picked children[0] (a static node) instead + // of the wildcard child at the end of the array. + out, found := tree.findCaseInsensitivePath("/aa", true) + if found { + t.Errorf("Expected no match for '/aa', but got: %s", string(out)) + } + + out, found = tree.findCaseInsensitivePath("/aa/aa/aa/aa", true) + if found { + t.Errorf("Expected no match for '/aa/aa/aa/aa', but got: %s", string(out)) + } + + // Case-insensitive lookup should match the static route /aa/aa + out, found = tree.findCaseInsensitivePath("/AA/AA", true) + if !found { + t.Error("Route '/AA/AA' not found via case-insensitive lookup") + } else if string(out) != "/aa/aa" { + t.Errorf("Wrong result for '/AA/AA': expected '/aa/aa', got: %s", string(out)) + } +} + +func TestTreeFindCaseInsensitivePathWildcardParamAndStaticChild(t *testing.T) { + tree := &node{} + + // Another variant: param route + static route under same prefix + routes := [...]string{ + "/prefix/:id", + "/prefix/xxx", + } + + for _, route := range routes { + recv := catchPanic(func() { + tree.addRoute(route, fakeHandler(route)) + }) + if recv != nil { + t.Fatalf("panic inserting route '%s': %v", route, recv) + } + } + + // Should NOT panic even for paths that don't match any route + out, found := tree.findCaseInsensitivePath("/prefix/a/b/c", true) + if found { + t.Errorf("Expected no match for '/prefix/a/b/c', but got: %s", string(out)) + } + + // Exact match should still work + out, found = tree.findCaseInsensitivePath("/prefix/xxx", true) + if !found { + t.Error("Route '/prefix/xxx' not found") + } else if string(out) != "/prefix/xxx" { + t.Errorf("Wrong result for '/prefix/xxx': %s", string(out)) + } + + // Case-insensitive match should work + out, found = tree.findCaseInsensitivePath("/PREFIX/XXX", true) + if !found { + t.Error("Route '/PREFIX/XXX' not found via case-insensitive lookup") + } else if string(out) != "/prefix/xxx" { + t.Errorf("Wrong result for '/PREFIX/XXX': expected '/prefix/xxx', got: %s", string(out)) + } + + // Param route should still match + out, found = tree.findCaseInsensitivePath("/prefix/something", true) + if !found { + t.Error("Route '/prefix/something' not found via param match") + } else if string(out) != "/prefix/something" { + t.Errorf("Wrong result for '/prefix/something': %s", string(out)) + } +} From 38534e2bf98a06e1f62d6b24384e90b5f78699bf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 28 Feb 2026 16:18:12 +0800 Subject: [PATCH 22/70] chore(deps): bump golang.org/x/net from 0.50.0 to 0.51.0 (#4548) Bumps [golang.org/x/net](https://github.com/golang/net) from 0.50.0 to 0.51.0. - [Commits](https://github.com/golang/net/commits) --- updated-dependencies: - dependency-name: golang.org/x/net dependency-version: 0.51.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Bo-Yi Wu --- go.mod | 6 ++---- go.sum | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 0f278049..4fe2ce4f 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,6 @@ module github.com/gin-gonic/gin -go 1.24.0 - -toolchain go1.24.7 +go 1.25.0 require ( github.com/bytedance/sonic v1.15.0 @@ -18,7 +16,7 @@ require ( github.com/stretchr/testify v1.11.1 github.com/ugorji/go/codec v1.3.1 go.mongodb.org/mongo-driver/v2 v2.5.0 - golang.org/x/net v0.50.0 + golang.org/x/net v0.51.0 google.golang.org/protobuf v1.36.10 ) diff --git a/go.sum b/go.sum index 71c07795..a75260ce 100644 --- a/go.sum +++ b/go.sum @@ -79,8 +79,8 @@ golang.org/x/arch v0.22.0 h1:c/Zle32i5ttqRXjdLyyHZESLD/bB90DCU1g9l/0YBDI= golang.org/x/arch v0.22.0/go.mod h1:dNHoOeKiyja7GTvF9NJS1l3Z2yntpQNzgrjh1cU103A= golang.org/x/crypto v0.48.0 h1:/VRzVqiRSggnhY7gNRxPauEQ5Drw9haKdM0jqfcCFts= golang.org/x/crypto v0.48.0/go.mod h1:r0kV5h3qnFPlQnBSrULhlsRfryS2pmewsg+XfMgkVos= -golang.org/x/net v0.50.0 h1:ucWh9eiCGyDR3vtzso0WMQinm2Dnt8cFMuQa9K33J60= -golang.org/x/net v0.50.0/go.mod h1:UgoSli3F/pBgdJBHCTc+tp3gmrU4XswgGRgtnwWTfyM= +golang.org/x/net v0.51.0 h1:94R/GTO7mt3/4wIKpcR5gkGmRLOuE/2hNGeWq/GBIFo= +golang.org/x/net v0.51.0/go.mod h1:aamm+2QF5ogm02fjy5Bb7CQ0WMt1/WVM7FtyaTLlA9Y= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k= golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= From ae3f524974fc4f55d18c9e7fae4614503c015226 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sat, 28 Feb 2026 17:37:02 +0800 Subject: [PATCH 23/70] ci: update Go version support to 1.25+ across CI and docs (#4550) * ci: update Go version support to 1.25+ across CI and docs - Remove Go 1.24 from CI test matrix to only support 1.25 and 1.26 - Update documentation to require Go version 1.25 or above Signed-off-by: appleboy * chore: increase required Go version for Gin to 1.25 - Update minimum required Go version for Gin from 1.24 to 1.25 - Revise related warning message and test expectations to match new version requirement Signed-off-by: appleboy --------- Signed-off-by: appleboy --- .github/workflows/gin.yml | 2 +- README.md | 2 +- debug.go | 4 ++-- debug_test.go | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/gin.yml b/.github/workflows/gin.yml index df774eab..d909d22d 100644 --- a/.github/workflows/gin.yml +++ b/.github/workflows/gin.yml @@ -33,7 +33,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest] - go: ["1.24", "1.25", "1.26"] + go: ["1.25", "1.26"] test-tags: [ "", diff --git a/README.md b/README.md index 1b9ab808..427bead5 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ Gin combines the simplicity of Express.js-style routing with Go's performance ch ### Prerequisites -- **Go version**: Gin requires [Go](https://go.dev/) version [1.24](https://go.dev/doc/devel/release#go1.24.0) or above +- **Go version**: Gin requires [Go](https://go.dev/) version [1.25](https://go.dev/doc/devel/release#go1.25.0) or above - **Basic Go knowledge**: Familiarity with Go syntax and package management is helpful ### Installation diff --git a/debug.go b/debug.go index 1cfa3721..753c1285 100644 --- a/debug.go +++ b/debug.go @@ -13,7 +13,7 @@ import ( "sync/atomic" ) -const ginSupportMinGoVer = 24 +const ginSupportMinGoVer = 25 var runtimeVersion = runtime.Version() @@ -80,7 +80,7 @@ func getMinVer(v string) (uint64, error) { func debugPrintWARNINGDefault() { if v, e := getMinVer(runtimeVersion); e == nil && v < ginSupportMinGoVer { - debugPrint(`[WARNING] Now Gin requires Go 1.24+. + debugPrint(`[WARNING] Now Gin requires Go 1.25+. `) } diff --git a/debug_test.go b/debug_test.go index dab02133..bf115ceb 100644 --- a/debug_test.go +++ b/debug_test.go @@ -121,7 +121,7 @@ func TestDebugPrintWARNINGDefaultWithUnsupportedVersion(t *testing.T) { debugPrintWARNINGDefault() SetMode(TestMode) }) - assert.Equal(t, "[GIN-debug] [WARNING] Now Gin requires Go 1.24+.\n\n[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.\n\n", re) + assert.Equal(t, "[GIN-debug] [WARNING] Now Gin requires Go 1.25+.\n\n[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.\n\n", re) } func TestDebugPrintWARNINGNew(t *testing.T) { From e292e5caa777bce70b66fe08c94cbe9cef3e2ec9 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sat, 28 Feb 2026 18:07:46 +0800 Subject: [PATCH 24/70] docs: document and finalize Gin v1.12.0 release (#4551) * docs: document and finalize Gin v1.12.0 release - Add changelog entries for the Gin v1.12.0 release, covering new features, enhancements, bug fixes, build updates, and dependency upgrades - Update all historical changelog entries to consistently use the same bullet style - Bump Gin version constant to v1.12.0 - Update README to announce Gin 1.12.0 instead of 1.11.0 Signed-off-by: appleboy * Update CHANGELOG.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Signed-off-by: appleboy Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- CHANGELOG.md | 574 +++++++++++++++++++++++++++------------------------ README.md | 2 +- version.go | 2 +- 3 files changed, 311 insertions(+), 267 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9451db39..e061e409 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,74 +1,124 @@ # Gin ChangeLog +## Gin v1.12.0 + +### Features + +- feat(render): add bson protocol ([#4145](https://github.com/gin-gonic/gin/pull/4145)) +- feat(context): add GetError and GetErrorSlice methods for error retrieval ([#4502](https://github.com/gin-gonic/gin/pull/4502)) +- feat(binding): add support for encoding.UnmarshalText in uri/query binding ([#4203](https://github.com/gin-gonic/gin/pull/4203)) +- feat(gin): add option to use escaped path ([#4420](https://github.com/gin-gonic/gin/pull/4420)) +- feat(context): add Protocol Buffers support to content negotiation ([#4423](https://github.com/gin-gonic/gin/pull/4423)) +- feat(context): implemented Delete method ([#38e7651](https://github.com/gin-gonic/gin/commit/38e7651)) +- feat(logger): color latency ([#4146](https://github.com/gin-gonic/gin/pull/4146)) + +### Enhancements + +- perf(tree): reduce allocations in findCaseInsensitivePath ([#4417](https://github.com/gin-gonic/gin/pull/4417)) +- perf(recovery): optimize line reading in stack function ([#4466](https://github.com/gin-gonic/gin/pull/4466)) +- perf(path): replace regex with custom functions in redirectTrailingSlash ([#4414](https://github.com/gin-gonic/gin/pull/4414)) +- perf(tree): optimize path parsing using strings.Count ([#4246](https://github.com/gin-gonic/gin/pull/4246)) +- chore(logger): allow skipping query string output ([#4547](https://github.com/gin-gonic/gin/pull/4547)) +- chore(context): always trust xff headers from unix socket ([#3359](https://github.com/gin-gonic/gin/pull/3359)) +- chore(response): prevent Flush() panic when the underlying ResponseWriter does not implement `http.Flusher` ([#4479](https://github.com/gin-gonic/gin/pull/4479)) +- refactor(recovery): smart error comparison ([#4142](https://github.com/gin-gonic/gin/pull/4142)) +- refactor(context): replace hardcoded localhost IPs with constants ([#4481](https://github.com/gin-gonic/gin/pull/4481)) +- refactor(utils): move util functions to utils.go ([#4467](https://github.com/gin-gonic/gin/pull/4467)) +- refactor(binding): use maps.Copy for cleaner map handling ([#4352](https://github.com/gin-gonic/gin/pull/4352)) +- refactor(context): using maps.Clone ([#4333](https://github.com/gin-gonic/gin/pull/4333)) +- refactor(ginS): use sync.OnceValue to simplify engine function ([#4314](https://github.com/gin-gonic/gin/pull/4314)) +- refactor: replace magic numbers with named constants in bodyAllowedForStatus ([#4529](https://github.com/gin-gonic/gin/pull/4529)) +- refactor: for loop can be modernized using range over int ([#4392](https://github.com/gin-gonic/gin/pull/4392)) + +### Bug Fixes + +- fix(tree): panic in findCaseInsensitivePathRec with RedirectFixedPath ([#4535](https://github.com/gin-gonic/gin/pull/4535)) +- fix(render): write content length in Data.Render ([#4206](https://github.com/gin-gonic/gin/pull/4206)) +- fix(context): ClientIP handling for multiple X-Forwarded-For header values ([#4472](https://github.com/gin-gonic/gin/pull/4472)) +- fix(binding): empty value error ([#2169](https://github.com/gin-gonic/gin/pull/2169)) +- fix(recover): suppress http.ErrAbortHandler in recover ([#4336](https://github.com/gin-gonic/gin/pull/4336)) +- fix(gin): literal colon routes not working with engine.Handler() ([#4415](https://github.com/gin-gonic/gin/pull/4415)) +- fix(gin): close os.File in RunFd to prevent resource leak ([#4422](https://github.com/gin-gonic/gin/pull/4422)) +- fix(response): refine hijack behavior for response lifecycle ([#4373](https://github.com/gin-gonic/gin/pull/4373)) +- fix(binding): improve empty slice/array handling in form binding ([#4380](https://github.com/gin-gonic/gin/pull/4380)) +- fix(debug): version mismatch ([#4403](https://github.com/gin-gonic/gin/pull/4403)) +- fix: correct typos, improve documentation clarity, and remove dead code ([#4511](https://github.com/gin-gonic/gin/pull/4511)) + +### Build process updates / CI + +- ci: update Go version support to 1.25+ across CI and docs ([#4550](https://github.com/gin-gonic/gin/pull/4550)) +- chore: bump minimum Go version to 1.24 and update workflows ([#4388](https://github.com/gin-gonic/gin/pull/4388)) +- chore(binding): upgrade bson dependency to mongo-driver v2 ([#4549](https://github.com/gin-gonic/gin/pull/4549)) + ## Gin v1.11.0 ### Features -* feat(gin): Experimental support for HTTP/3 using quic-go/quic-go ([#3210](https://github.com/gin-gonic/gin/pull/3210)) -* feat(form): add array collection format in form binding ([#3986](https://github.com/gin-gonic/gin/pull/3986)), add custom string slice for form tag unmarshal ([#3970](https://github.com/gin-gonic/gin/pull/3970)) -* feat(binding): add BindPlain ([#3904](https://github.com/gin-gonic/gin/pull/3904)) -* feat(fs): Export, test and document OnlyFilesFS ([#3939](https://github.com/gin-gonic/gin/pull/3939)) -* feat(binding): add support for unixMilli and unixMicro ([#4190](https://github.com/gin-gonic/gin/pull/4190)) -* feat(form): Support default values for collections in form binding ([#4048](https://github.com/gin-gonic/gin/pull/4048)) -* feat(context): GetXxx added support for more go native types ([#3633](https://github.com/gin-gonic/gin/pull/3633)) +- feat(gin): Experimental support for HTTP/3 using quic-go/quic-go ([#3210](https://github.com/gin-gonic/gin/pull/3210)) +- feat(form): add array collection format in form binding ([#3986](https://github.com/gin-gonic/gin/pull/3986)), add custom string slice for form tag unmarshal ([#3970](https://github.com/gin-gonic/gin/pull/3970)) +- feat(binding): add BindPlain ([#3904](https://github.com/gin-gonic/gin/pull/3904)) +- feat(fs): Export, test and document OnlyFilesFS ([#3939](https://github.com/gin-gonic/gin/pull/3939)) +- feat(binding): add support for unixMilli and unixMicro ([#4190](https://github.com/gin-gonic/gin/pull/4190)) +- feat(form): Support default values for collections in form binding ([#4048](https://github.com/gin-gonic/gin/pull/4048)) +- feat(context): GetXxx added support for more go native types ([#3633](https://github.com/gin-gonic/gin/pull/3633)) ### Enhancements -* perf(context): optimize getMapFromFormData performance ([#4339](https://github.com/gin-gonic/gin/pull/4339)) -* refactor(tree): replace string(/) with "/" in node.insertChild ([#4354](https://github.com/gin-gonic/gin/pull/4354)) -* refactor(render): remove headers parameter from writeHeader ([#4353](https://github.com/gin-gonic/gin/pull/4353)) -* refactor(context): simplify "GetType()" functions ([#4080](https://github.com/gin-gonic/gin/pull/4080)) -* refactor(slice): simplify SliceValidationError Error method ([#3910](https://github.com/gin-gonic/gin/pull/3910)) -* refactor(context):Avoid using filepath.Dir twice in SaveUploadedFile ([#4181](https://github.com/gin-gonic/gin/pull/4181)) -* refactor(context): refactor context handling and improve test robustness ([#4066](https://github.com/gin-gonic/gin/pull/4066)) -* refactor(binding): use strings.Cut to replace strings.Index ([#3522](https://github.com/gin-gonic/gin/pull/3522)) -* refactor(context): add an optional permission parameter to SaveUploadedFile ([#4068](https://github.com/gin-gonic/gin/pull/4068)) -* refactor(context): verify URL is Non-nil in initQueryCache() ([#3969](https://github.com/gin-gonic/gin/pull/3969)) -* refactor(context): YAML judgment logic in Negotiate ([#3966](https://github.com/gin-gonic/gin/pull/3966)) -* tree: replace the self-defined 'min' to official one ([#3975](https://github.com/gin-gonic/gin/pull/3975)) -* context: Remove redundant filepath.Dir usage ([#4181](https://github.com/gin-gonic/gin/pull/4181)) +- perf(context): optimize getMapFromFormData performance ([#4339](https://github.com/gin-gonic/gin/pull/4339)) +- refactor(tree): replace string(/) with "/" in node.insertChild ([#4354](https://github.com/gin-gonic/gin/pull/4354)) +- refactor(render): remove headers parameter from writeHeader ([#4353](https://github.com/gin-gonic/gin/pull/4353)) +- refactor(context): simplify "GetType()" functions ([#4080](https://github.com/gin-gonic/gin/pull/4080)) +- refactor(slice): simplify SliceValidationError Error method ([#3910](https://github.com/gin-gonic/gin/pull/3910)) +- refactor(context):Avoid using filepath.Dir twice in SaveUploadedFile ([#4181](https://github.com/gin-gonic/gin/pull/4181)) +- refactor(context): refactor context handling and improve test robustness ([#4066](https://github.com/gin-gonic/gin/pull/4066)) +- refactor(binding): use strings.Cut to replace strings.Index ([#3522](https://github.com/gin-gonic/gin/pull/3522)) +- refactor(context): add an optional permission parameter to SaveUploadedFile ([#4068](https://github.com/gin-gonic/gin/pull/4068)) +- refactor(context): verify URL is Non-nil in initQueryCache() ([#3969](https://github.com/gin-gonic/gin/pull/3969)) +- refactor(context): YAML judgment logic in Negotiate ([#3966](https://github.com/gin-gonic/gin/pull/3966)) +- tree: replace the self-defined 'min' to official one ([#3975](https://github.com/gin-gonic/gin/pull/3975)) +- context: Remove redundant filepath.Dir usage ([#4181](https://github.com/gin-gonic/gin/pull/4181)) ### Bug Fixes -* fix: prevent middleware re-entry issue in HandleContext ([#3987](https://github.com/gin-gonic/gin/pull/3987)) -* fix(binding): prevent duplicate decoding and add validation in decodeToml ([#4193](https://github.com/gin-gonic/gin/pull/4193)) -* fix(gin): Do not panic when handling method not allowed on empty tree ([#4003](https://github.com/gin-gonic/gin/pull/4003)) -* fix(gin): data race warning for gin mode ([#1580](https://github.com/gin-gonic/gin/pull/1580)) -* fix(context): verify URL is Non-nil in initQueryCache() ([#3969](https://github.com/gin-gonic/gin/pull/3969)) -* fix(context): YAML judgment logic in Negotiate ([#3966](https://github.com/gin-gonic/gin/pull/3966)) -* fix(context): check handler is nil ([#3413](https://github.com/gin-gonic/gin/pull/3413)) -* fix(readme): fix broken link to English documentation ([#4222](https://github.com/gin-gonic/gin/pull/4222)) -* fix(tree): Keep panic infos consistent when wildcard type build faild ([#4077](https://github.com/gin-gonic/gin/pull/4077)) +- fix: prevent middleware re-entry issue in HandleContext ([#3987](https://github.com/gin-gonic/gin/pull/3987)) +- fix(binding): prevent duplicate decoding and add validation in decodeToml ([#4193](https://github.com/gin-gonic/gin/pull/4193)) +- fix(gin): Do not panic when handling method not allowed on empty tree ([#4003](https://github.com/gin-gonic/gin/pull/4003)) +- fix(gin): data race warning for gin mode ([#1580](https://github.com/gin-gonic/gin/pull/1580)) +- fix(context): verify URL is Non-nil in initQueryCache() ([#3969](https://github.com/gin-gonic/gin/pull/3969)) +- fix(context): YAML judgment logic in Negotiate ([#3966](https://github.com/gin-gonic/gin/pull/3966)) +- fix(context): check handler is nil ([#3413](https://github.com/gin-gonic/gin/pull/3413)) +- fix(readme): fix broken link to English documentation ([#4222](https://github.com/gin-gonic/gin/pull/4222)) +- fix(tree): Keep panic infos consistent when wildcard type build faild ([#4077](https://github.com/gin-gonic/gin/pull/4077)) ### Build process updates / CI -* ci: integrate Trivy vulnerability scanning into CI workflow ([#4359](https://github.com/gin-gonic/gin/pull/4359)) -* ci: support Go 1.25 in CI/CD ([#4341](https://github.com/gin-gonic/gin/pull/4341)) -* build(deps): upgrade github.com/bytedance/sonic from v1.13.2 to v1.14.0 ([#4342](https://github.com/gin-gonic/gin/pull/4342)) -* ci: add Go version 1.24 to GitHub Actions ([#4154](https://github.com/gin-gonic/gin/pull/4154)) -* build: update Gin minimum Go version to 1.21 ([#3960](https://github.com/gin-gonic/gin/pull/3960)) -* ci(lint): enable new linters (testifylint, usestdlibvars, perfsprint, etc.) ([#4010](https://github.com/gin-gonic/gin/pull/4010), [#4091](https://github.com/gin-gonic/gin/pull/4091), [#4090](https://github.com/gin-gonic/gin/pull/4090)) -* ci(lint): update workflows and improve test request consistency ([#4126](https://github.com/gin-gonic/gin/pull/4126)) +- ci: integrate Trivy vulnerability scanning into CI workflow ([#4359](https://github.com/gin-gonic/gin/pull/4359)) +- ci: support Go 1.25 in CI/CD ([#4341](https://github.com/gin-gonic/gin/pull/4341)) +- build(deps): upgrade github.com/bytedance/sonic from v1.13.2 to v1.14.0 ([#4342](https://github.com/gin-gonic/gin/pull/4342)) +- ci: add Go version 1.24 to GitHub Actions ([#4154](https://github.com/gin-gonic/gin/pull/4154)) +- build: update Gin minimum Go version to 1.21 ([#3960](https://github.com/gin-gonic/gin/pull/3960)) +- ci(lint): enable new linters (testifylint, usestdlibvars, perfsprint, etc.) ([#4010](https://github.com/gin-gonic/gin/pull/4010), [#4091](https://github.com/gin-gonic/gin/pull/4091), [#4090](https://github.com/gin-gonic/gin/pull/4090)) +- ci(lint): update workflows and improve test request consistency ([#4126](https://github.com/gin-gonic/gin/pull/4126)) ### Dependency updates -* chore(deps): bump google.golang.org/protobuf from 1.36.6 to 1.36.9 ([#4346](https://github.com/gin-gonic/gin/pull/4346), [#4356](https://github.com/gin-gonic/gin/pull/4356)) -* chore(deps): bump github.com/stretchr/testify from 1.10.0 to 1.11.1 ([#4347](https://github.com/gin-gonic/gin/pull/4347)) -* chore(deps): bump actions/setup-go from 5 to 6 ([#4351](https://github.com/gin-gonic/gin/pull/4351)) -* chore(deps): bump github.com/quic-go/quic-go from 0.53.0 to 0.54.0 ([#4328](https://github.com/gin-gonic/gin/pull/4328)) -* chore(deps): bump golang.org/x/net from 0.33.0 to 0.38.0 ([#4178](https://github.com/gin-gonic/gin/pull/4178), [#4221](https://github.com/gin-gonic/gin/pull/4221)) -* chore(deps): bump github.com/go-playground/validator/v10 from 10.20.0 to 10.22.1 ([#4052](https://github.com/gin-gonic/gin/pull/4052)) +- chore(deps): bump google.golang.org/protobuf from 1.36.6 to 1.36.9 ([#4346](https://github.com/gin-gonic/gin/pull/4346), [#4356](https://github.com/gin-gonic/gin/pull/4356)) +- chore(deps): bump github.com/stretchr/testify from 1.10.0 to 1.11.1 ([#4347](https://github.com/gin-gonic/gin/pull/4347)) +- chore(deps): bump actions/setup-go from 5 to 6 ([#4351](https://github.com/gin-gonic/gin/pull/4351)) +- chore(deps): bump github.com/quic-go/quic-go from 0.53.0 to 0.54.0 ([#4328](https://github.com/gin-gonic/gin/pull/4328)) +- chore(deps): bump golang.org/x/net from 0.33.0 to 0.38.0 ([#4178](https://github.com/gin-gonic/gin/pull/4178), [#4221](https://github.com/gin-gonic/gin/pull/4221)) +- chore(deps): bump github.com/go-playground/validator/v10 from 10.20.0 to 10.22.1 ([#4052](https://github.com/gin-gonic/gin/pull/4052)) ### Documentation updates -* docs(changelog): update release notes for Gin v1.10.1 ([#4360](https://github.com/gin-gonic/gin/pull/4360)) -* docs: Fixing English grammar mistakes and awkward sentence structure in doc/doc.md ([#4207](https://github.com/gin-gonic/gin/pull/4207)) -* docs: update documentation and release notes for Gin v1.10.0 ([#3953](https://github.com/gin-gonic/gin/pull/3953)) -* docs: fix typo in Gin Quick Start ([#3997](https://github.com/gin-gonic/gin/pull/3997)) -* docs: fix comment and link issues ([#4205](https://github.com/gin-gonic/gin/pull/4205), [#3938](https://github.com/gin-gonic/gin/pull/3938)) -* docs: fix route group example code ([#4020](https://github.com/gin-gonic/gin/pull/4020)) -* docs(readme): add Portuguese documentation ([#4078](https://github.com/gin-gonic/gin/pull/4078)) -* docs(context): fix some function names in comment ([#4079](https://github.com/gin-gonic/gin/pull/4079)) +- docs(changelog): update release notes for Gin v1.10.1 ([#4360](https://github.com/gin-gonic/gin/pull/4360)) +- docs: Fixing English grammar mistakes and awkward sentence structure in doc/doc.md ([#4207](https://github.com/gin-gonic/gin/pull/4207)) +- docs: update documentation and release notes for Gin v1.10.0 ([#3953](https://github.com/gin-gonic/gin/pull/3953)) +- docs: fix typo in Gin Quick Start ([#3997](https://github.com/gin-gonic/gin/pull/3997)) +- docs: fix comment and link issues ([#4205](https://github.com/gin-gonic/gin/pull/4205), [#3938](https://github.com/gin-gonic/gin/pull/3938)) +- docs: fix route group example code ([#4020](https://github.com/gin-gonic/gin/pull/4020)) +- docs(readme): add Portuguese documentation ([#4078](https://github.com/gin-gonic/gin/pull/4078)) +- docs(context): fix some function names in comment ([#4079](https://github.com/gin-gonic/gin/pull/4079)) --- @@ -76,377 +126,377 @@ ### Features -* refactor: strengthen HTTPS security and improve code organization -* feat(binding): Support custom BindUnmarshaler for binding. (#3933) +- refactor: strengthen HTTPS security and improve code organization +- feat(binding): Support custom BindUnmarshaler for binding. (#3933) ### Enhancements -* chore(deps): bump github.com/bytedance/sonic from 1.11.3 to 1.11.6 (#3940) -* chore(deps): bump golangci/golangci-lint-action from 4 to 5 (#3941) -* chore: update external dependencies to latest versions (#3950) -* chore: update various Go dependencies to latest versions (#3901) -* chore: refactor configuration files for better readability (#3951) -* chore: update changelog categories and improve documentation (#3917) -* feat: update version constant to v1.10.0 (#3952) +- chore(deps): bump github.com/bytedance/sonic from 1.11.3 to 1.11.6 (#3940) +- chore(deps): bump golangci/golangci-lint-action from 4 to 5 (#3941) +- chore: update external dependencies to latest versions (#3950) +- chore: update various Go dependencies to latest versions (#3901) +- chore: refactor configuration files for better readability (#3951) +- chore: update changelog categories and improve documentation (#3917) +- feat: update version constant to v1.10.0 (#3952) ### Build process updates -* ci(release): refactor changelog regex patterns and exclusions (#3914) -* ci(Makefile): vet command add .PHONY (#3915) +- ci(release): refactor changelog regex patterns and exclusions (#3914) +- ci(Makefile): vet command add .PHONY (#3915) ## Gin v1.10.0 ### Features -* feat(auth): add proxy-server authentication (#3877) (@EndlessParadox1) -* feat(bind): ShouldBindBodyWith shortcut and change doc (#3871) (@RedCrazyGhost) -* feat(binding): Support custom BindUnmarshaler for binding. (#3933) (@dkkb) -* feat(binding): support override default binding implement (#3514) (@ssfyn) -* feat(engine): Added `OptionFunc` and `With` (#3572) (@flc1125) -* feat(logger): ability to skip logs based on user-defined logic (#3593) (@palvaneh) +- feat(auth): add proxy-server authentication (#3877) (@EndlessParadox1) +- feat(bind): ShouldBindBodyWith shortcut and change doc (#3871) (@RedCrazyGhost) +- feat(binding): Support custom BindUnmarshaler for binding. (#3933) (@dkkb) +- feat(binding): support override default binding implement (#3514) (@ssfyn) +- feat(engine): Added `OptionFunc` and `With` (#3572) (@flc1125) +- feat(logger): ability to skip logs based on user-defined logic (#3593) (@palvaneh) ### Bug fixes -* Revert "fix(uri): query binding bug (#3236)" (#3899) (@appleboy) -* fix(binding): binding error while not upload file (#3819) (#3820) (@clearcodecn) -* fix(binding): dereference pointer to struct (#3199) (@echovl) -* fix(context): make context Value method adhere to Go standards (#3897) (@FarmerChillax) -* fix(engine): fix unit test (#3878) (@flc1125) -* fix(header): Allow header according to RFC 7231 (HTTP 405) (#3759) (@Crocmagnon) -* fix(route): Add fullPath in context copy (#3784) (@KarthikReddyPuli) -* fix(router): catch-all conflicting wildcard (#3812) (@FirePing32) -* fix(sec): upgrade golang.org/x/crypto to 0.17.0 (#3832) (@chncaption) -* fix(tree): correctly expand the capacity of params (#3502) (@georgijd-form3) -* fix(uri): query binding bug (#3236) (@illiafox) -* fix: Add pointer support for url query params (#3659) (#3666) (@omkar-foss) -* fix: protect Context.Keys map when call Copy method (#3873) (@kingcanfish) +- Revert "fix(uri): query binding bug (#3236)" (#3899) (@appleboy) +- fix(binding): binding error while not upload file (#3819) (#3820) (@clearcodecn) +- fix(binding): dereference pointer to struct (#3199) (@echovl) +- fix(context): make context Value method adhere to Go standards (#3897) (@FarmerChillax) +- fix(engine): fix unit test (#3878) (@flc1125) +- fix(header): Allow header according to RFC 7231 (HTTP 405) (#3759) (@Crocmagnon) +- fix(route): Add fullPath in context copy (#3784) (@KarthikReddyPuli) +- fix(router): catch-all conflicting wildcard (#3812) (@FirePing32) +- fix(sec): upgrade golang.org/x/crypto to 0.17.0 (#3832) (@chncaption) +- fix(tree): correctly expand the capacity of params (#3502) (@georgijd-form3) +- fix(uri): query binding bug (#3236) (@illiafox) +- fix: Add pointer support for url query params (#3659) (#3666) (@omkar-foss) +- fix: protect Context.Keys map when call Copy method (#3873) (@kingcanfish) ### Enhancements -* chore(CI): update release args (#3595) (@qloog) -* chore(IP): add TrustedPlatform constant for Fly.io. (#3839) (@ab) -* chore(debug): add ability to override the debugPrint statement (#2337) (@josegonzalez) -* chore(deps): update dependencies to latest versions (#3835) (@appleboy) -* chore(header): Add support for RFC 9512: application/yaml (#3851) (@vincentbernat) -* chore(http): use white color for HTTP 1XX (#3741) (@viralparmarme) -* chore(optimize): the ShouldBindUri method of the Context struct (#3911) (@1911860538) -* chore(perf): Optimize the Copy method of the Context struct (#3859) (@1911860538) -* chore(refactor): modify interface check way (#3855) (@demoManito) -* chore(request): check reader if it's nil before reading (#3419) (@noahyao1024) -* chore(security): upgrade Protobuf for CVE-2024-24786 (#3893) (@Fotkurz) -* chore: refactor CI and update dependencies (#3848) (@appleboy) -* chore: refactor configuration files for better readability (#3951) (@appleboy) -* chore: update GitHub Actions configuration (#3792) (@appleboy) -* chore: update changelog categories and improve documentation (#3917) (@appleboy) -* chore: update dependencies to latest versions (#3694) (@appleboy) -* chore: update external dependencies to latest versions (#3950) (@appleboy) -* chore: update various Go dependencies to latest versions (#3901) (@appleboy) +- chore(CI): update release args (#3595) (@qloog) +- chore(IP): add TrustedPlatform constant for Fly.io. (#3839) (@ab) +- chore(debug): add ability to override the debugPrint statement (#2337) (@josegonzalez) +- chore(deps): update dependencies to latest versions (#3835) (@appleboy) +- chore(header): Add support for RFC 9512: application/yaml (#3851) (@vincentbernat) +- chore(http): use white color for HTTP 1XX (#3741) (@viralparmarme) +- chore(optimize): the ShouldBindUri method of the Context struct (#3911) (@1911860538) +- chore(perf): Optimize the Copy method of the Context struct (#3859) (@1911860538) +- chore(refactor): modify interface check way (#3855) (@demoManito) +- chore(request): check reader if it's nil before reading (#3419) (@noahyao1024) +- chore(security): upgrade Protobuf for CVE-2024-24786 (#3893) (@Fotkurz) +- chore: refactor CI and update dependencies (#3848) (@appleboy) +- chore: refactor configuration files for better readability (#3951) (@appleboy) +- chore: update GitHub Actions configuration (#3792) (@appleboy) +- chore: update changelog categories and improve documentation (#3917) (@appleboy) +- chore: update dependencies to latest versions (#3694) (@appleboy) +- chore: update external dependencies to latest versions (#3950) (@appleboy) +- chore: update various Go dependencies to latest versions (#3901) (@appleboy) ### Build process updates -* build(codecov): Added a codecov configuration (#3891) (@flc1125) -* ci(Makefile): vet command add .PHONY (#3915) (@imalasong) -* ci(lint): update tooling and workflows for consistency (#3834) (@appleboy) -* ci(release): refactor changelog regex patterns and exclusions (#3914) (@appleboy) -* ci(testing): add go1.22 version (#3842) (@appleboy) +- build(codecov): Added a codecov configuration (#3891) (@flc1125) +- ci(Makefile): vet command add .PHONY (#3915) (@imalasong) +- ci(lint): update tooling and workflows for consistency (#3834) (@appleboy) +- ci(release): refactor changelog regex patterns and exclusions (#3914) (@appleboy) +- ci(testing): add go1.22 version (#3842) (@appleboy) ### Documentation updates -* docs(context): Added deprecation comments to BindWith (#3880) (@flc1125) -* docs(middleware): comments to function `BasicAuthForProxy` (#3881) (@EndlessParadox1) -* docs: Add document to constant `AuthProxyUserKey` and `BasicAuthForProxy`. (#3887) (@EndlessParadox1) -* docs: fix typo in comment (#3868) (@testwill) -* docs: fix typo in function documentation (#3872) (@TotomiEcio) -* docs: remove redundant comments (#3765) (@WeiTheShinobi) -* feat: update version constant to v1.10.0 (#3952) (@appleboy) +- docs(context): Added deprecation comments to BindWith (#3880) (@flc1125) +- docs(middleware): comments to function `BasicAuthForProxy` (#3881) (@EndlessParadox1) +- docs: Add document to constant `AuthProxyUserKey` and `BasicAuthForProxy`. (#3887) (@EndlessParadox1) +- docs: fix typo in comment (#3868) (@testwill) +- docs: fix typo in function documentation (#3872) (@TotomiEcio) +- docs: remove redundant comments (#3765) (@WeiTheShinobi) +- feat: update version constant to v1.10.0 (#3952) (@appleboy) ### Others -* Upgrade golang.org/x/net -> v0.13.0 (#3684) (@cpcf) -* test(git): gitignore add develop tools (#3370) (@demoManito) -* test(http): use constant instead of numeric literal (#3863) (@testwill) -* test(path): Optimize unit test execution results (#3883) (@flc1125) -* test(render): increased unit tests coverage (#3691) (@araujo88) +- Upgrade golang.org/x/net -> v0.13.0 (#3684) (@cpcf) +- test(git): gitignore add develop tools (#3370) (@demoManito) +- test(http): use constant instead of numeric literal (#3863) (@testwill) +- test(path): Optimize unit test execution results (#3883) (@flc1125) +- test(render): increased unit tests coverage (#3691) (@araujo88) ## Gin v1.9.1 ### BUG FIXES -* fix Request.Context() checks [#3512](https://github.com/gin-gonic/gin/pull/3512) +- fix Request.Context() checks [#3512](https://github.com/gin-gonic/gin/pull/3512) ### SECURITY -* fix lack of escaping of filename in Content-Disposition [#3556](https://github.com/gin-gonic/gin/pull/3556) +- fix lack of escaping of filename in Content-Disposition [#3556](https://github.com/gin-gonic/gin/pull/3556) ### ENHANCEMENTS -* refactor: use bytes.ReplaceAll directly [#3455](https://github.com/gin-gonic/gin/pull/3455) -* convert strings and slices using the officially recommended way [#3344](https://github.com/gin-gonic/gin/pull/3344) -* improve render code coverage [#3525](https://github.com/gin-gonic/gin/pull/3525) +- refactor: use bytes.ReplaceAll directly [#3455](https://github.com/gin-gonic/gin/pull/3455) +- convert strings and slices using the officially recommended way [#3344](https://github.com/gin-gonic/gin/pull/3344) +- improve render code coverage [#3525](https://github.com/gin-gonic/gin/pull/3525) ### DOCS -* docs: changed documentation link for trusted proxies [#3575](https://github.com/gin-gonic/gin/pull/3575) -* chore: improve linting, testing, and GitHub Actions setup [#3583](https://github.com/gin-gonic/gin/pull/3583) +- docs: changed documentation link for trusted proxies [#3575](https://github.com/gin-gonic/gin/pull/3575) +- chore: improve linting, testing, and GitHub Actions setup [#3583](https://github.com/gin-gonic/gin/pull/3583) ## Gin v1.9.0 ### BREAK CHANGES -* Stop useless panicking in context and render [#2150](https://github.com/gin-gonic/gin/pull/2150) +- Stop useless panicking in context and render [#2150](https://github.com/gin-gonic/gin/pull/2150) ### BUG FIXES -* fix(router): tree bug where loop index is not decremented. [#3460](https://github.com/gin-gonic/gin/pull/3460) -* fix(context): panic on NegotiateFormat - index out of range [#3397](https://github.com/gin-gonic/gin/pull/3397) -* Add escape logic for header [#3500](https://github.com/gin-gonic/gin/pull/3500) and [#3503](https://github.com/gin-gonic/gin/pull/3503) +- fix(router): tree bug where loop index is not decremented. [#3460](https://github.com/gin-gonic/gin/pull/3460) +- fix(context): panic on NegotiateFormat - index out of range [#3397](https://github.com/gin-gonic/gin/pull/3397) +- Add escape logic for header [#3500](https://github.com/gin-gonic/gin/pull/3500) and [#3503](https://github.com/gin-gonic/gin/pull/3503) ### SECURITY -* Fix the GO-2022-0969 and GO-2022-0288 vulnerabilities [#3333](https://github.com/gin-gonic/gin/pull/3333) -* fix(security): vulnerability GO-2023-1571 [#3505](https://github.com/gin-gonic/gin/pull/3505) +- Fix the GO-2022-0969 and GO-2022-0288 vulnerabilities [#3333](https://github.com/gin-gonic/gin/pull/3333) +- fix(security): vulnerability GO-2023-1571 [#3505](https://github.com/gin-gonic/gin/pull/3505) ### ENHANCEMENTS -* feat: add sonic json support [#3184](https://github.com/gin-gonic/gin/pull/3184) -* chore(file): Creates a directory named path [#3316](https://github.com/gin-gonic/gin/pull/3316) -* fix: modify interface check way [#3327](https://github.com/gin-gonic/gin/pull/3327) -* remove deprecated of package io/ioutil [#3395](https://github.com/gin-gonic/gin/pull/3395) -* refactor: avoid calling strings.ToLower twice [#3343](https://github.com/gin-gonic/gin/pull/3433) -* console logger HTTP status code bug fixed [#3453](https://github.com/gin-gonic/gin/pull/3453) -* chore(yaml): upgrade dependency to v3 version [#3456](https://github.com/gin-gonic/gin/pull/3456) -* chore(router): match method added to routergroup for multiple HTTP methods supporting [#3464](https://github.com/gin-gonic/gin/pull/3464) -* chore(http): add support for go1.20 http.rwUnwrapper to gin.responseWriter [#3489](https://github.com/gin-gonic/gin/pull/3489) +- feat: add sonic json support [#3184](https://github.com/gin-gonic/gin/pull/3184) +- chore(file): Creates a directory named path [#3316](https://github.com/gin-gonic/gin/pull/3316) +- fix: modify interface check way [#3327](https://github.com/gin-gonic/gin/pull/3327) +- remove deprecated of package io/ioutil [#3395](https://github.com/gin-gonic/gin/pull/3395) +- refactor: avoid calling strings.ToLower twice [#3343](https://github.com/gin-gonic/gin/pull/3433) +- console logger HTTP status code bug fixed [#3453](https://github.com/gin-gonic/gin/pull/3453) +- chore(yaml): upgrade dependency to v3 version [#3456](https://github.com/gin-gonic/gin/pull/3456) +- chore(router): match method added to routergroup for multiple HTTP methods supporting [#3464](https://github.com/gin-gonic/gin/pull/3464) +- chore(http): add support for go1.20 http.rwUnwrapper to gin.responseWriter [#3489](https://github.com/gin-gonic/gin/pull/3489) ### DOCS -* docs: update markdown format [#3260](https://github.com/gin-gonic/gin/pull/3260) -* docs(readme): Add the TOML rendering example [#3400](https://github.com/gin-gonic/gin/pull/3400) -* docs(readme): move more example to docs/doc.md [#3449](https://github.com/gin-gonic/gin/pull/3449) -* docs: update markdown format [#3446](https://github.com/gin-gonic/gin/pull/3446) +- docs: update markdown format [#3260](https://github.com/gin-gonic/gin/pull/3260) +- docs(readme): Add the TOML rendering example [#3400](https://github.com/gin-gonic/gin/pull/3400) +- docs(readme): move more example to docs/doc.md [#3449](https://github.com/gin-gonic/gin/pull/3449) +- docs: update markdown format [#3446](https://github.com/gin-gonic/gin/pull/3446) ## Gin v1.8.2 ### BUG FIXES -* fix(route): redirectSlash bug ([#3227]((https://github.com/gin-gonic/gin/pull/3227))) -* fix(engine): missing route params for CreateTestContext ([#2778]((https://github.com/gin-gonic/gin/pull/2778))) ([#2803]((https://github.com/gin-gonic/gin/pull/2803))) +- fix(route): redirectSlash bug ([#3227](<(https://github.com/gin-gonic/gin/pull/3227)>)) +- fix(engine): missing route params for CreateTestContext ([#2778](<(https://github.com/gin-gonic/gin/pull/2778)>)) ([#2803](<(https://github.com/gin-gonic/gin/pull/2803)>)) ### SECURITY -* Fix the GO-2022-1144 vulnerability ([#3432]((https://github.com/gin-gonic/gin/pull/3432))) +- Fix the GO-2022-1144 vulnerability ([#3432](<(https://github.com/gin-gonic/gin/pull/3432)>)) ## Gin v1.8.1 ### ENHANCEMENTS -* feat(context): add ContextWithFallback feature flag [#3172](https://github.com/gin-gonic/gin/pull/3172) +- feat(context): add ContextWithFallback feature flag [#3172](https://github.com/gin-gonic/gin/pull/3172) ## Gin v1.8.0 ### BREAK CHANGES -* TrustedProxies: Add default IPv6 support and refactor [#2967](https://github.com/gin-gonic/gin/pull/2967). Please replace `RemoteIP() (net.IP, bool)` with `RemoteIP() net.IP` -* gin.Context with fallback value from gin.Context.Request.Context() [#2751](https://github.com/gin-gonic/gin/pull/2751) +- TrustedProxies: Add default IPv6 support and refactor [#2967](https://github.com/gin-gonic/gin/pull/2967). Please replace `RemoteIP() (net.IP, bool)` with `RemoteIP() net.IP` +- gin.Context with fallback value from gin.Context.Request.Context() [#2751](https://github.com/gin-gonic/gin/pull/2751) ### BUG FIXES -* Fixed SetOutput() panics on go 1.17 [#2861](https://github.com/gin-gonic/gin/pull/2861) -* Fix: wrong when wildcard follows named param [#2983](https://github.com/gin-gonic/gin/pull/2983) -* Fix: missing sameSite when do context.reset() [#3123](https://github.com/gin-gonic/gin/pull/3123) +- Fixed SetOutput() panics on go 1.17 [#2861](https://github.com/gin-gonic/gin/pull/2861) +- Fix: wrong when wildcard follows named param [#2983](https://github.com/gin-gonic/gin/pull/2983) +- Fix: missing sameSite when do context.reset() [#3123](https://github.com/gin-gonic/gin/pull/3123) ### ENHANCEMENTS -* Use Header() instead of deprecated HeaderMap [#2694](https://github.com/gin-gonic/gin/pull/2694) -* RouterGroup.Handle regular match optimization of http method [#2685](https://github.com/gin-gonic/gin/pull/2685) -* Add support go-json, another drop-in json replacement [#2680](https://github.com/gin-gonic/gin/pull/2680) -* Use errors.New to replace fmt.Errorf will much better [#2707](https://github.com/gin-gonic/gin/pull/2707) -* Use Duration.Truncate for truncating precision [#2711](https://github.com/gin-gonic/gin/pull/2711) -* Get client IP when using Cloudflare [#2723](https://github.com/gin-gonic/gin/pull/2723) -* Optimize code adjust [#2700](https://github.com/gin-gonic/gin/pull/2700/files) -* Optimize code and reduce code cyclomatic complexity [#2737](https://github.com/gin-gonic/gin/pull/2737) -* Improve sliceValidateError.Error performance [#2765](https://github.com/gin-gonic/gin/pull/2765) -* Support custom struct tag [#2720](https://github.com/gin-gonic/gin/pull/2720) -* Improve router group tests [#2787](https://github.com/gin-gonic/gin/pull/2787) -* Fallback Context.Deadline() Context.Done() Context.Err() to Context.Request.Context() [#2769](https://github.com/gin-gonic/gin/pull/2769) -* Some codes optimize [#2830](https://github.com/gin-gonic/gin/pull/2830) [#2834](https://github.com/gin-gonic/gin/pull/2834) [#2838](https://github.com/gin-gonic/gin/pull/2838) [#2837](https://github.com/gin-gonic/gin/pull/2837) [#2788](https://github.com/gin-gonic/gin/pull/2788) [#2848](https://github.com/gin-gonic/gin/pull/2848) [#2851](https://github.com/gin-gonic/gin/pull/2851) [#2701](https://github.com/gin-gonic/gin/pull/2701) -* TrustedProxies: Add default IPv6 support and refactor [#2967](https://github.com/gin-gonic/gin/pull/2967) -* Test(route): expose performRequest func [#3012](https://github.com/gin-gonic/gin/pull/3012) -* Support h2c with prior knowledge [#1398](https://github.com/gin-gonic/gin/pull/1398) -* Feat attachment filename support utf8 [#3071](https://github.com/gin-gonic/gin/pull/3071) -* Feat: add StaticFileFS [#2749](https://github.com/gin-gonic/gin/pull/2749) -* Feat(context): return GIN Context from Value method [#2825](https://github.com/gin-gonic/gin/pull/2825) -* Feat: automatically SetMode to TestMode when run go test [#3139](https://github.com/gin-gonic/gin/pull/3139) -* Add TOML bining for gin [#3081](https://github.com/gin-gonic/gin/pull/3081) -* IPv6 add default trusted proxies [#3033](https://github.com/gin-gonic/gin/pull/3033) +- Use Header() instead of deprecated HeaderMap [#2694](https://github.com/gin-gonic/gin/pull/2694) +- RouterGroup.Handle regular match optimization of http method [#2685](https://github.com/gin-gonic/gin/pull/2685) +- Add support go-json, another drop-in json replacement [#2680](https://github.com/gin-gonic/gin/pull/2680) +- Use errors.New to replace fmt.Errorf will much better [#2707](https://github.com/gin-gonic/gin/pull/2707) +- Use Duration.Truncate for truncating precision [#2711](https://github.com/gin-gonic/gin/pull/2711) +- Get client IP when using Cloudflare [#2723](https://github.com/gin-gonic/gin/pull/2723) +- Optimize code adjust [#2700](https://github.com/gin-gonic/gin/pull/2700/files) +- Optimize code and reduce code cyclomatic complexity [#2737](https://github.com/gin-gonic/gin/pull/2737) +- Improve sliceValidateError.Error performance [#2765](https://github.com/gin-gonic/gin/pull/2765) +- Support custom struct tag [#2720](https://github.com/gin-gonic/gin/pull/2720) +- Improve router group tests [#2787](https://github.com/gin-gonic/gin/pull/2787) +- Fallback Context.Deadline() Context.Done() Context.Err() to Context.Request.Context() [#2769](https://github.com/gin-gonic/gin/pull/2769) +- Some codes optimize [#2830](https://github.com/gin-gonic/gin/pull/2830) [#2834](https://github.com/gin-gonic/gin/pull/2834) [#2838](https://github.com/gin-gonic/gin/pull/2838) [#2837](https://github.com/gin-gonic/gin/pull/2837) [#2788](https://github.com/gin-gonic/gin/pull/2788) [#2848](https://github.com/gin-gonic/gin/pull/2848) [#2851](https://github.com/gin-gonic/gin/pull/2851) [#2701](https://github.com/gin-gonic/gin/pull/2701) +- TrustedProxies: Add default IPv6 support and refactor [#2967](https://github.com/gin-gonic/gin/pull/2967) +- Test(route): expose performRequest func [#3012](https://github.com/gin-gonic/gin/pull/3012) +- Support h2c with prior knowledge [#1398](https://github.com/gin-gonic/gin/pull/1398) +- Feat attachment filename support utf8 [#3071](https://github.com/gin-gonic/gin/pull/3071) +- Feat: add StaticFileFS [#2749](https://github.com/gin-gonic/gin/pull/2749) +- Feat(context): return GIN Context from Value method [#2825](https://github.com/gin-gonic/gin/pull/2825) +- Feat: automatically SetMode to TestMode when run go test [#3139](https://github.com/gin-gonic/gin/pull/3139) +- Add TOML bining for gin [#3081](https://github.com/gin-gonic/gin/pull/3081) +- IPv6 add default trusted proxies [#3033](https://github.com/gin-gonic/gin/pull/3033) ### DOCS -* Add note about nomsgpack tag to the readme [#2703](https://github.com/gin-gonic/gin/pull/2703) +- Add note about nomsgpack tag to the readme [#2703](https://github.com/gin-gonic/gin/pull/2703) ## Gin v1.7.7 ### BUG FIXES -* Fixed X-Forwarded-For unsafe handling of CVE-2020-28483 [#2844](https://github.com/gin-gonic/gin/pull/2844), closed issue [#2862](https://github.com/gin-gonic/gin/issues/2862). -* Tree: updated the code logic for `latestNode` [#2897](https://github.com/gin-gonic/gin/pull/2897), closed issue [#2894](https://github.com/gin-gonic/gin/issues/2894) [#2878](https://github.com/gin-gonic/gin/issues/2878). -* Tree: fixed the misplacement of adding slashes [#2847](https://github.com/gin-gonic/gin/pull/2847), closed issue [#2843](https://github.com/gin-gonic/gin/issues/2843). -* Tree: fixed tsr with mixed static and wildcard paths [#2924](https://github.com/gin-gonic/gin/pull/2924), closed issue [#2918](https://github.com/gin-gonic/gin/issues/2918). +- Fixed X-Forwarded-For unsafe handling of CVE-2020-28483 [#2844](https://github.com/gin-gonic/gin/pull/2844), closed issue [#2862](https://github.com/gin-gonic/gin/issues/2862). +- Tree: updated the code logic for `latestNode` [#2897](https://github.com/gin-gonic/gin/pull/2897), closed issue [#2894](https://github.com/gin-gonic/gin/issues/2894) [#2878](https://github.com/gin-gonic/gin/issues/2878). +- Tree: fixed the misplacement of adding slashes [#2847](https://github.com/gin-gonic/gin/pull/2847), closed issue [#2843](https://github.com/gin-gonic/gin/issues/2843). +- Tree: fixed tsr with mixed static and wildcard paths [#2924](https://github.com/gin-gonic/gin/pull/2924), closed issue [#2918](https://github.com/gin-gonic/gin/issues/2918). ### ENHANCEMENTS -* TrustedProxies: make it backward-compatible [#2887](https://github.com/gin-gonic/gin/pull/2887), closed issue [#2819](https://github.com/gin-gonic/gin/issues/2819). -* TrustedPlatform: provide custom options for another CDN services [#2906](https://github.com/gin-gonic/gin/pull/2906). +- TrustedProxies: make it backward-compatible [#2887](https://github.com/gin-gonic/gin/pull/2887), closed issue [#2819](https://github.com/gin-gonic/gin/issues/2819). +- TrustedPlatform: provide custom options for another CDN services [#2906](https://github.com/gin-gonic/gin/pull/2906). ### DOCS -* NoMethod: added usage annotation ([#2832](https://github.com/gin-gonic/gin/pull/2832#issuecomment-929954463)). +- NoMethod: added usage annotation ([#2832](https://github.com/gin-gonic/gin/pull/2832#issuecomment-929954463)). ## Gin v1.7.6 ### BUG FIXES -* bump new release to fix v1.7.5 release error by using v1.7.4 codes. +- bump new release to fix v1.7.5 release error by using v1.7.4 codes. ## Gin v1.7.4 ### BUG FIXES -* bump new release to fix checksum mismatch +- bump new release to fix checksum mismatch ## Gin v1.7.3 ### BUG FIXES -* fix level 1 router match [#2767](https://github.com/gin-gonic/gin/issues/2767), [#2796](https://github.com/gin-gonic/gin/issues/2796) +- fix level 1 router match [#2767](https://github.com/gin-gonic/gin/issues/2767), [#2796](https://github.com/gin-gonic/gin/issues/2796) ## Gin v1.7.2 ### BUG FIXES -* Fix conflict between param and exact path [#2706](https://github.com/gin-gonic/gin/issues/2706). Close issue [#2682](https://github.com/gin-gonic/gin/issues/2682) [#2696](https://github.com/gin-gonic/gin/issues/2696). +- Fix conflict between param and exact path [#2706](https://github.com/gin-gonic/gin/issues/2706). Close issue [#2682](https://github.com/gin-gonic/gin/issues/2682) [#2696](https://github.com/gin-gonic/gin/issues/2696). ## Gin v1.7.1 ### BUG FIXES -* fix: data race with trustedCIDRs from [#2674](https://github.com/gin-gonic/gin/issues/2674)([#2675](https://github.com/gin-gonic/gin/pull/2675)) +- fix: data race with trustedCIDRs from [#2674](https://github.com/gin-gonic/gin/issues/2674)([#2675](https://github.com/gin-gonic/gin/pull/2675)) ## Gin v1.7.0 ### BUG FIXES -* fix compile error from [#2572](https://github.com/gin-gonic/gin/pull/2572) ([#2600](https://github.com/gin-gonic/gin/pull/2600)) -* fix: print headers without Authorization header on broken pipe ([#2528](https://github.com/gin-gonic/gin/pull/2528)) -* fix(tree): reassign fullpath when register new node ([#2366](https://github.com/gin-gonic/gin/pull/2366)) +- fix compile error from [#2572](https://github.com/gin-gonic/gin/pull/2572) ([#2600](https://github.com/gin-gonic/gin/pull/2600)) +- fix: print headers without Authorization header on broken pipe ([#2528](https://github.com/gin-gonic/gin/pull/2528)) +- fix(tree): reassign fullpath when register new node ([#2366](https://github.com/gin-gonic/gin/pull/2366)) ### ENHANCEMENTS -* Support params and exact routes without creating conflicts ([#2663](https://github.com/gin-gonic/gin/pull/2663)) -* chore: improve render string performance ([#2365](https://github.com/gin-gonic/gin/pull/2365)) -* Sync route tree to httprouter latest code ([#2368](https://github.com/gin-gonic/gin/pull/2368)) -* chore: rename getQueryCache/getFormCache to initQueryCache/initFormCa ([#2375](https://github.com/gin-gonic/gin/pull/2375)) -* chore(performance): improve countParams ([#2378](https://github.com/gin-gonic/gin/pull/2378)) -* Remove some functions that have the same effect as the bytes package ([#2387](https://github.com/gin-gonic/gin/pull/2387)) -* update:SetMode function ([#2321](https://github.com/gin-gonic/gin/pull/2321)) -* remove an unused type SecureJSONPrefix ([#2391](https://github.com/gin-gonic/gin/pull/2391)) -* Add a redirect sample for POST method ([#2389](https://github.com/gin-gonic/gin/pull/2389)) -* Add CustomRecovery builtin middleware ([#2322](https://github.com/gin-gonic/gin/pull/2322)) -* binding: avoid 2038 problem on 32-bit architectures ([#2450](https://github.com/gin-gonic/gin/pull/2450)) -* Prevent panic in Context.GetQuery() when there is no Request ([#2412](https://github.com/gin-gonic/gin/pull/2412)) -* Add GetUint and GetUint64 method on gin.context ([#2487](https://github.com/gin-gonic/gin/pull/2487)) -* update content-disposition header to MIME-style ([#2512](https://github.com/gin-gonic/gin/pull/2512)) -* reduce allocs and improve the render `WriteString` ([#2508](https://github.com/gin-gonic/gin/pull/2508)) -* implement ".Unwrap() error" on Error type ([#2525](https://github.com/gin-gonic/gin/pull/2525)) ([#2526](https://github.com/gin-gonic/gin/pull/2526)) -* Allow bind with a map[string]string ([#2484](https://github.com/gin-gonic/gin/pull/2484)) -* chore: update tree ([#2371](https://github.com/gin-gonic/gin/pull/2371)) -* Support binding for slice/array obj [Rewrite] ([#2302](https://github.com/gin-gonic/gin/pull/2302)) -* basic auth: fix timing oracle ([#2609](https://github.com/gin-gonic/gin/pull/2609)) -* Add mixed param and non-param paths (port of httprouter[#329](https://github.com/gin-gonic/gin/pull/329)) ([#2663](https://github.com/gin-gonic/gin/pull/2663)) -* feat(engine): add trustedproxies and remoteIP ([#2632](https://github.com/gin-gonic/gin/pull/2632)) +- Support params and exact routes without creating conflicts ([#2663](https://github.com/gin-gonic/gin/pull/2663)) +- chore: improve render string performance ([#2365](https://github.com/gin-gonic/gin/pull/2365)) +- Sync route tree to httprouter latest code ([#2368](https://github.com/gin-gonic/gin/pull/2368)) +- chore: rename getQueryCache/getFormCache to initQueryCache/initFormCa ([#2375](https://github.com/gin-gonic/gin/pull/2375)) +- chore(performance): improve countParams ([#2378](https://github.com/gin-gonic/gin/pull/2378)) +- Remove some functions that have the same effect as the bytes package ([#2387](https://github.com/gin-gonic/gin/pull/2387)) +- update:SetMode function ([#2321](https://github.com/gin-gonic/gin/pull/2321)) +- remove an unused type SecureJSONPrefix ([#2391](https://github.com/gin-gonic/gin/pull/2391)) +- Add a redirect sample for POST method ([#2389](https://github.com/gin-gonic/gin/pull/2389)) +- Add CustomRecovery builtin middleware ([#2322](https://github.com/gin-gonic/gin/pull/2322)) +- binding: avoid 2038 problem on 32-bit architectures ([#2450](https://github.com/gin-gonic/gin/pull/2450)) +- Prevent panic in Context.GetQuery() when there is no Request ([#2412](https://github.com/gin-gonic/gin/pull/2412)) +- Add GetUint and GetUint64 method on gin.context ([#2487](https://github.com/gin-gonic/gin/pull/2487)) +- update content-disposition header to MIME-style ([#2512](https://github.com/gin-gonic/gin/pull/2512)) +- reduce allocs and improve the render `WriteString` ([#2508](https://github.com/gin-gonic/gin/pull/2508)) +- implement ".Unwrap() error" on Error type ([#2525](https://github.com/gin-gonic/gin/pull/2525)) ([#2526](https://github.com/gin-gonic/gin/pull/2526)) +- Allow bind with a map[string]string ([#2484](https://github.com/gin-gonic/gin/pull/2484)) +- chore: update tree ([#2371](https://github.com/gin-gonic/gin/pull/2371)) +- Support binding for slice/array obj [Rewrite] ([#2302](https://github.com/gin-gonic/gin/pull/2302)) +- basic auth: fix timing oracle ([#2609](https://github.com/gin-gonic/gin/pull/2609)) +- Add mixed param and non-param paths (port of httprouter[#329](https://github.com/gin-gonic/gin/pull/329)) ([#2663](https://github.com/gin-gonic/gin/pull/2663)) +- feat(engine): add trustedproxies and remoteIP ([#2632](https://github.com/gin-gonic/gin/pull/2632)) ## Gin v1.6.3 ### ENHANCEMENTS - * Improve performance: Change `*sync.RWMutex` to `sync.RWMutex` in context. [#2351](https://github.com/gin-gonic/gin/pull/2351) +- Improve performance: Change `*sync.RWMutex` to `sync.RWMutex` in context. [#2351](https://github.com/gin-gonic/gin/pull/2351) ## Gin v1.6.2 ### BUG FIXES - * fix missing initial sync.RWMutex [#2305](https://github.com/gin-gonic/gin/pull/2305) +- fix missing initial sync.RWMutex [#2305](https://github.com/gin-gonic/gin/pull/2305) ### ENHANCEMENTS - * Add set samesite in cookie. [#2306](https://github.com/gin-gonic/gin/pull/2306) +- Add set samesite in cookie. [#2306](https://github.com/gin-gonic/gin/pull/2306) ## Gin v1.6.1 ### BUG FIXES - * Revert "fix accept incoming network connections" [#2294](https://github.com/gin-gonic/gin/pull/2294) +- Revert "fix accept incoming network connections" [#2294](https://github.com/gin-gonic/gin/pull/2294) ## Gin v1.6.0 ### BREAKING - * chore(performance): Improve performance for adding RemoveExtraSlash flag [#2159](https://github.com/gin-gonic/gin/pull/2159) - * drop support govendor [#2148](https://github.com/gin-gonic/gin/pull/2148) - * Added support for SameSite cookie flag [#1615](https://github.com/gin-gonic/gin/pull/1615) +- chore(performance): Improve performance for adding RemoveExtraSlash flag [#2159](https://github.com/gin-gonic/gin/pull/2159) +- drop support govendor [#2148](https://github.com/gin-gonic/gin/pull/2148) +- Added support for SameSite cookie flag [#1615](https://github.com/gin-gonic/gin/pull/1615) ### FEATURES - * add yaml negotiation [#2220](https://github.com/gin-gonic/gin/pull/2220) - * FileFromFS [#2112](https://github.com/gin-gonic/gin/pull/2112) +- add yaml negotiation [#2220](https://github.com/gin-gonic/gin/pull/2220) +- FileFromFS [#2112](https://github.com/gin-gonic/gin/pull/2112) ### BUG FIXES - * Unix Socket Handling [#2280](https://github.com/gin-gonic/gin/pull/2280) - * Use json marshall in context json to fix breaking new line issue. Fixes #2209 [#2228](https://github.com/gin-gonic/gin/pull/2228) - * fix accept incoming network connections [#2216](https://github.com/gin-gonic/gin/pull/2216) - * Fixed a bug in the calculation of the maximum number of parameters [#2166](https://github.com/gin-gonic/gin/pull/2166) - * [FIX] allow empty headers on DataFromReader [#2121](https://github.com/gin-gonic/gin/pull/2121) - * Add mutex for protect Context.Keys map [#1391](https://github.com/gin-gonic/gin/pull/1391) +- Unix Socket Handling [#2280](https://github.com/gin-gonic/gin/pull/2280) +- Use json marshall in context json to fix breaking new line issue. Fixes #2209 [#2228](https://github.com/gin-gonic/gin/pull/2228) +- fix accept incoming network connections [#2216](https://github.com/gin-gonic/gin/pull/2216) +- Fixed a bug in the calculation of the maximum number of parameters [#2166](https://github.com/gin-gonic/gin/pull/2166) +- [FIX] allow empty headers on DataFromReader [#2121](https://github.com/gin-gonic/gin/pull/2121) +- Add mutex for protect Context.Keys map [#1391](https://github.com/gin-gonic/gin/pull/1391) ### ENHANCEMENTS - * Add mitigation for log injection [#2277](https://github.com/gin-gonic/gin/pull/2277) - * tree: range over nodes values [#2229](https://github.com/gin-gonic/gin/pull/2229) - * tree: remove duplicate assignment [#2222](https://github.com/gin-gonic/gin/pull/2222) - * chore: upgrade go-isatty and json-iterator/go [#2215](https://github.com/gin-gonic/gin/pull/2215) - * path: sync code with httprouter [#2212](https://github.com/gin-gonic/gin/pull/2212) - * Use zero-copy approach to convert types between string and byte slice [#2206](https://github.com/gin-gonic/gin/pull/2206) - * Reuse bytes when cleaning the URL paths [#2179](https://github.com/gin-gonic/gin/pull/2179) - * tree: remove one else statement [#2177](https://github.com/gin-gonic/gin/pull/2177) - * tree: sync httprouter update (#2173) (#2172) [#2171](https://github.com/gin-gonic/gin/pull/2171) - * tree: sync part httprouter codes and reduce if/else [#2163](https://github.com/gin-gonic/gin/pull/2163) - * use http method constant [#2155](https://github.com/gin-gonic/gin/pull/2155) - * upgrade go-validator to v10 [#2149](https://github.com/gin-gonic/gin/pull/2149) - * Refactor redirect request in gin.go [#1970](https://github.com/gin-gonic/gin/pull/1970) - * Add build tag nomsgpack [#1852](https://github.com/gin-gonic/gin/pull/1852) +- Add mitigation for log injection [#2277](https://github.com/gin-gonic/gin/pull/2277) +- tree: range over nodes values [#2229](https://github.com/gin-gonic/gin/pull/2229) +- tree: remove duplicate assignment [#2222](https://github.com/gin-gonic/gin/pull/2222) +- chore: upgrade go-isatty and json-iterator/go [#2215](https://github.com/gin-gonic/gin/pull/2215) +- path: sync code with httprouter [#2212](https://github.com/gin-gonic/gin/pull/2212) +- Use zero-copy approach to convert types between string and byte slice [#2206](https://github.com/gin-gonic/gin/pull/2206) +- Reuse bytes when cleaning the URL paths [#2179](https://github.com/gin-gonic/gin/pull/2179) +- tree: remove one else statement [#2177](https://github.com/gin-gonic/gin/pull/2177) +- tree: sync httprouter update (#2173) (#2172) [#2171](https://github.com/gin-gonic/gin/pull/2171) +- tree: sync part httprouter codes and reduce if/else [#2163](https://github.com/gin-gonic/gin/pull/2163) +- use http method constant [#2155](https://github.com/gin-gonic/gin/pull/2155) +- upgrade go-validator to v10 [#2149](https://github.com/gin-gonic/gin/pull/2149) +- Refactor redirect request in gin.go [#1970](https://github.com/gin-gonic/gin/pull/1970) +- Add build tag nomsgpack [#1852](https://github.com/gin-gonic/gin/pull/1852) ### DOCS - * docs(path): improve comments [#2223](https://github.com/gin-gonic/gin/pull/2223) - * Renew README to fit the modification of SetCookie method [#2217](https://github.com/gin-gonic/gin/pull/2217) - * Fix spelling [#2202](https://github.com/gin-gonic/gin/pull/2202) - * Remove broken link from README. [#2198](https://github.com/gin-gonic/gin/pull/2198) - * Update docs on Context.Done(), Context.Deadline() and Context.Err() [#2196](https://github.com/gin-gonic/gin/pull/2196) - * Update validator to v10 [#2190](https://github.com/gin-gonic/gin/pull/2190) - * upgrade go-validator to v10 for README [#2189](https://github.com/gin-gonic/gin/pull/2189) - * Update to currently output [#2188](https://github.com/gin-gonic/gin/pull/2188) - * Fix "Custom Validators" example [#2186](https://github.com/gin-gonic/gin/pull/2186) - * Add project to README [#2165](https://github.com/gin-gonic/gin/pull/2165) - * docs(benchmarks): for gin v1.5 [#2153](https://github.com/gin-gonic/gin/pull/2153) - * Changed wording for clarity in README.md [#2122](https://github.com/gin-gonic/gin/pull/2122) +- docs(path): improve comments [#2223](https://github.com/gin-gonic/gin/pull/2223) +- Renew README to fit the modification of SetCookie method [#2217](https://github.com/gin-gonic/gin/pull/2217) +- Fix spelling [#2202](https://github.com/gin-gonic/gin/pull/2202) +- Remove broken link from README. [#2198](https://github.com/gin-gonic/gin/pull/2198) +- Update docs on Context.Done(), Context.Deadline() and Context.Err() [#2196](https://github.com/gin-gonic/gin/pull/2196) +- Update validator to v10 [#2190](https://github.com/gin-gonic/gin/pull/2190) +- upgrade go-validator to v10 for README [#2189](https://github.com/gin-gonic/gin/pull/2189) +- Update to currently output [#2188](https://github.com/gin-gonic/gin/pull/2188) +- Fix "Custom Validators" example [#2186](https://github.com/gin-gonic/gin/pull/2186) +- Add project to README [#2165](https://github.com/gin-gonic/gin/pull/2165) +- docs(benchmarks): for gin v1.5 [#2153](https://github.com/gin-gonic/gin/pull/2153) +- Changed wording for clarity in README.md [#2122](https://github.com/gin-gonic/gin/pull/2122) ### MISC - * ci support go1.14 [#2262](https://github.com/gin-gonic/gin/pull/2262) - * chore: upgrade depend version [#2231](https://github.com/gin-gonic/gin/pull/2231) - * Drop support go1.10 [#2147](https://github.com/gin-gonic/gin/pull/2147) - * fix comment in `mode.go` [#2129](https://github.com/gin-gonic/gin/pull/2129) +- ci support go1.14 [#2262](https://github.com/gin-gonic/gin/pull/2262) +- chore: upgrade depend version [#2231](https://github.com/gin-gonic/gin/pull/2231) +- Drop support go1.10 [#2147](https://github.com/gin-gonic/gin/pull/2147) +- fix comment in `mode.go` [#2129](https://github.com/gin-gonic/gin/pull/2129) ## Gin v1.5.0 @@ -485,14 +535,14 @@ ### Gin v1.4.0 -- [NEW] Support for [Go Modules](https://github.com/golang/go/wiki/Modules) [#1569](https://github.com/gin-gonic/gin/pull/1569) +- [NEW] Support for [Go Modules](https://github.com/golang/go/wiki/Modules) [#1569](https://github.com/gin-gonic/gin/pull/1569) - [NEW] Refactor of form mapping multipart request [#1829](https://github.com/gin-gonic/gin/pull/1829) - [FIX] Truncate Latency precision in long running request [#1830](https://github.com/gin-gonic/gin/pull/1830) - [FIX] IsTerm flag should not be affected by DisableConsoleColor method. [#1802](https://github.com/gin-gonic/gin/pull/1802) - [NEW] Supporting file binding [#1264](https://github.com/gin-gonic/gin/pull/1264) - [NEW] Add support for mapping arrays [#1797](https://github.com/gin-gonic/gin/pull/1797) - [FIX] Readme updates [#1793](https://github.com/gin-gonic/gin/pull/1793) [#1788](https://github.com/gin-gonic/gin/pull/1788) [1789](https://github.com/gin-gonic/gin/pull/1789) -- [FIX] StaticFS: Fixed Logging two log lines on 404. [#1805](https://github.com/gin-gonic/gin/pull/1805), [#1804](https://github.com/gin-gonic/gin/pull/1804) +- [FIX] StaticFS: Fixed Logging two log lines on 404. [#1805](https://github.com/gin-gonic/gin/pull/1805), [#1804](https://github.com/gin-gonic/gin/pull/1804) - [NEW] Make context.Keys available as LogFormatterParams [#1779](https://github.com/gin-gonic/gin/pull/1779) - [NEW] Use internal/json for Marshal/Unmarshal [#1791](https://github.com/gin-gonic/gin/pull/1791) - [NEW] Support mapping time.Duration [#1794](https://github.com/gin-gonic/gin/pull/1794) @@ -524,7 +574,7 @@ - [NEW] RunFd method to run http.Server through a file descriptor [#1609](https://github.com/gin-gonic/gin/pull/1609) - [NEW] Yaml binding support [#1618](https://github.com/gin-gonic/gin/pull/1618) - [FIX] Pass MaxMultipartMemory when FormFile is called [#1600](https://github.com/gin-gonic/gin/pull/1600) -- [FIX] LoadHTML* tests [#1559](https://github.com/gin-gonic/gin/pull/1559) +- [FIX] LoadHTML\* tests [#1559](https://github.com/gin-gonic/gin/pull/1559) - [FIX] Removed use of sync.pool from HandleContext [#1565](https://github.com/gin-gonic/gin/pull/1565) - [FIX] Format output log to os.Stderr [#1571](https://github.com/gin-gonic/gin/pull/1571) - [FIX] Make logger use a yellow background and a darkgray text for legibility [#1570](https://github.com/gin-gonic/gin/pull/1570) @@ -539,7 +589,6 @@ - [FIX] Add BindXML and ShouldBindXML [#1485](https://github.com/gin-gonic/gin/pull/1485) - [NEW] Upgrade dependency libraries [#1491](https://github.com/gin-gonic/gin/pull/1491) - ## Gin v1.3.0 - [NEW] Add [`func (*Context) QueryMap`](https://godoc.org/github.com/gin-gonic/gin#Context.QueryMap), [`func (*Context) GetQueryMap`](https://godoc.org/github.com/gin-gonic/gin#Context.GetQueryMap), [`func (*Context) PostFormMap`](https://godoc.org/github.com/gin-gonic/gin#Context.PostFormMap) and [`func (*Context) GetPostFormMap`](https://godoc.org/github.com/gin-gonic/gin#Context.GetPostFormMap) to support `type map[string]string` as query string or form parameters, see [#1383](https://github.com/gin-gonic/gin/pull/1383) @@ -637,7 +686,6 @@ - [FIX] Error implements the json.Marshaller interface - [FIX] MIT license in every file - ## Gin 1.0rc1 (May 22, 2015) - [PERFORMANCE] Zero allocation router @@ -681,7 +729,6 @@ - [FIX] Hijacking http - [FIX] Better support for Google App Engine (using log instead of fmt) - ## Gin 0.6 (Mar 9, 2015) - [NEW] Support multipart/form-data @@ -691,14 +738,12 @@ - [FIX] Unsigned integers in binding - [FIX] Improve color logger - ## Gin 0.5 (Feb 7, 2015) - [NEW] Content Negotiation - [FIX] Solved security bug that allow a client to spoof ip - [FIX] Fix unexported/ignored fields in binding - ## Gin 0.4 (Aug 21, 2014) - [NEW] Development mode @@ -707,7 +752,6 @@ - [FIX] Deferring WriteHeader() - [FIX] Improved documentation for model binding - ## Gin 0.3 (Jul 18, 2014) - [PERFORMANCE] Normal log and error log are printed in the same call. @@ -725,8 +769,8 @@ - [FIX] Renaming Context.Req to Context.Request - [FIX] Check application/x-www-form-urlencoded when parsing form - ## Gin 0.2b (Jul 08, 2014) + - [PERFORMANCE] Using sync.Pool to allocatio/gc overhead - [NEW] Travis CI integration - [NEW] Completely new logger diff --git a/README.md b/README.md index 427bead5..3c815afa 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ [![Open Source Helpers](https://www.codetriage.com/gin-gonic/gin/badges/users.svg)](https://www.codetriage.com/gin-gonic/gin) [![Release](https://img.shields.io/github/release/gin-gonic/gin.svg?style=flat-square)](https://github.com/gin-gonic/gin/releases) -## 📰 [Announcing Gin 1.11.0!](https://gin-gonic.com/en/blog/news/gin-1-11-0-release-announcement/) +## 📰 [Announcing Gin 1.12.0!](https://gin-gonic.com/en/blog/news/gin-1-12-0-release-announcement/) Read about the latest features and improvements in Gin 1.11.0 on our official blog. diff --git a/version.go b/version.go index 8049058c..5b54e68a 100644 --- a/version.go +++ b/version.go @@ -5,4 +5,4 @@ package gin // Version is the current gin framework's version. -const Version = "v1.11.0" +const Version = "v1.12.0" From 73726dc606796a025971fe451f0aa6f1b9b847f6 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sat, 28 Feb 2026 18:10:09 +0800 Subject: [PATCH 25/70] docs: update documentation to reflect Go version changes (#4552) - Remove the changelog entry about bumping minimum Go version to 1.24 and updating workflows Signed-off-by: appleboy --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e061e409..95bc2f84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,7 +47,6 @@ ### Build process updates / CI - ci: update Go version support to 1.25+ across CI and docs ([#4550](https://github.com/gin-gonic/gin/pull/4550)) -- chore: bump minimum Go version to 1.24 and update workflows ([#4388](https://github.com/gin-gonic/gin/pull/4388)) - chore(binding): upgrade bson dependency to mongo-driver v2 ([#4549](https://github.com/gin-gonic/gin/pull/4549)) ## Gin v1.11.0 From ff00c01e674259bff6ccaab02564362cd419096b Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sat, 28 Feb 2026 20:38:49 +0800 Subject: [PATCH 26/70] docs: revise and expand Gin 1.12.0 release announcement (#4554) - Update release announcement section to introduce Gin 1.12.0 - Provide a more detailed description of new features and improvements in version 1.12.0 Signed-off-by: appleboy --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3c815afa..d6492c06 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,9 @@ [![Open Source Helpers](https://www.codetriage.com/gin-gonic/gin/badges/users.svg)](https://www.codetriage.com/gin-gonic/gin) [![Release](https://img.shields.io/github/release/gin-gonic/gin.svg?style=flat-square)](https://github.com/gin-gonic/gin/releases) -## 📰 [Announcing Gin 1.12.0!](https://gin-gonic.com/en/blog/news/gin-1-12-0-release-announcement/) +## 📰 Gin 1.12.0 is now available! -Read about the latest features and improvements in Gin 1.11.0 on our official blog. +We're excited to announce the release of **[Gin 1.12.0](https://gin-gonic.com/en/blog/news/gin-1-12-0-release-announcement/)**! This release brings new features, performance improvements, and important bug fixes. Check out the [release announcement](https://gin-gonic.com/en/blog/news/gin-1-12-0-release-announcement/) on our official blog for the full details. --- From 052d1a79aafe3f04078a2716f8e77d4340308383 Mon Sep 17 00:00:00 2001 From: Aum Patel <150163017+Aum-Patel1234@users.noreply.github.com> Date: Sat, 28 Feb 2026 18:34:54 +0530 Subject: [PATCH 27/70] feat(render): add PDF renderer and tests (#4491) * render: add PDF renderer and tests * render: update PDF renderer copyright header * test: add PDF rendering tests including 204 No Content in context_test.go --- context.go | 6 ++++++ context_test.go | 27 +++++++++++++++++++++++++++ render/pdf.go | 26 ++++++++++++++++++++++++++ render/render.go | 1 + render/render_test.go | 16 ++++++++++++++++ 5 files changed, 76 insertions(+) create mode 100644 render/pdf.go diff --git a/context.go b/context.go index 92fb3704..5174033e 100644 --- a/context.go +++ b/context.go @@ -1224,6 +1224,12 @@ func (c *Context) XML(code int, obj any) { c.Render(code, render.XML{Data: obj}) } +// PDF writes the given PDF binary data into the response body. +// It also sets the Content-Type as "application/pdf". +func (c *Context) PDF(code int, data []byte) { + c.Render(code, render.PDF{Data: data}) +} + // YAML serializes the given struct as YAML into the response body. func (c *Context) YAML(code int, obj any) { c.Render(code, render.YAML{Data: obj}) diff --git a/context_test.go b/context_test.go index 44db7475..ef60379d 100644 --- a/context_test.go +++ b/context_test.go @@ -1320,6 +1320,33 @@ func TestContextRenderNoContentXML(t *testing.T) { assert.Equal(t, "application/xml; charset=utf-8", w.Header().Get("Content-Type")) } +// TestContextRenderPDF tests that the response is serialized as PDF +// and Content-Type is set to application/pdf +func TestContextRenderPDF(t *testing.T) { + w := httptest.NewRecorder() + c, _ := CreateTestContext(w) + + data := []byte("%Test pdf content") + c.PDF(http.StatusCreated, data) + + assert.Equal(t, http.StatusCreated, w.Code) + assert.Equal(t, data, w.Body.Bytes()) + assert.Equal(t, "application/pdf", w.Header().Get("Content-Type")) +} + +// Tests that no PDF is rendered if code is 204 +func TestContextRenderNoContentPDF(t *testing.T) { + w := httptest.NewRecorder() + c, _ := CreateTestContext(w) + + data := []byte("%Test pdf content") + c.PDF(http.StatusNoContent, data) + + assert.Equal(t, http.StatusNoContent, w.Code) + assert.Empty(t, w.Body.Bytes()) + assert.Equal(t, "application/pdf", w.Header().Get("Content-Type")) +} + // TestContextRenderString tests that the response is returned // with Content-Type set to text/plain func TestContextRenderString(t *testing.T) { diff --git a/render/pdf.go b/render/pdf.go new file mode 100644 index 00000000..04dcc1f5 --- /dev/null +++ b/render/pdf.go @@ -0,0 +1,26 @@ +// Copyright 2026 Gin Core Team. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + +package render + +import "net/http" + +// PDF contains the given PDF binary data. +type PDF struct { + Data []byte +} + +var pdfContentType = []string{"application/pdf"} + +// Render (PDF) writes PDF data with custom ContentType. +func (r PDF) Render(w http.ResponseWriter) error { + r.WriteContentType(w) + _, err := w.Write(r.Data) + return err +} + +// WriteContentType (PDF) writes PDF ContentType for response. +func (r PDF) WriteContentType(w http.ResponseWriter) { + writeContentType(w, pdfContentType) +} diff --git a/render/render.go b/render/render.go index 4bdcfa23..28bc0f5d 100644 --- a/render/render.go +++ b/render/render.go @@ -31,6 +31,7 @@ var ( _ Render = (*AsciiJSON)(nil) _ Render = (*ProtoBuf)(nil) _ Render = (*TOML)(nil) + _ Render = (*PDF)(nil) ) func writeContentType(w http.ResponseWriter, value []string) { diff --git a/render/render_test.go b/render/render_test.go index b48ab3d3..f63878b9 100644 --- a/render/render_test.go +++ b/render/render_test.go @@ -466,6 +466,22 @@ func TestRenderXMLError(t *testing.T) { assert.Contains(t, err.Error(), "xml: unsupported type: chan int") } +func TestRenderPDF(t *testing.T) { + w := httptest.NewRecorder() + data := []byte("%Test pdf content") + + pdf := PDF{data} + + pdf.WriteContentType(w) + assert.Equal(t, "application/pdf", w.Header().Get("Content-Type")) + + err := pdf.Render(w) + require.NoError(t, err) + + assert.Equal(t, data, w.Body.Bytes()) + assert.Equal(t, "application/pdf", w.Header().Get("Content-Type")) +} + func TestRenderRedirect(t *testing.T) { req, err := http.NewRequest(http.MethodGet, "/test-redirect", nil) require.NoError(t, err) From a39670fb7b2d18ffabe41d59bd58935a387d817a Mon Sep 17 00:00:00 2001 From: Max Katz Date: Sat, 28 Feb 2026 17:46:37 +0400 Subject: [PATCH 28/70] docs(license): update license period (#4130) Co-authored-by: Bo-Yi Wu --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 1ff7f370..49770f0c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014 Manuel Martínez-Almeida +Copyright (c) 2014-present Manuel Martínez-Almeida Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From cb2b764cc8a8613b84c44c45b8b2b1ba9da6244d Mon Sep 17 00:00:00 2001 From: HolynnChen <854560673@qq.com> Date: Sat, 28 Feb 2026 21:55:28 +0800 Subject: [PATCH 29/70] test(make): modify test folder and test command in Makefile (#4465) Co-authored-by: Bo-Yi Wu --- Makefile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 1a7de86b..3c2da3b1 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ GO_VERSION=$(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2) PACKAGES ?= $(shell $(GO) list ./...) VETPACKAGES ?= $(shell $(GO) list ./... | grep -v /examples/) GOFILES := $(shell find . -name "*.go") -TESTFOLDER := $(shell $(GO) list ./... | grep -E 'gin$$|binding$$|render$$' | grep -v examples) +TESTFOLDER := $(shell $(GO) list ./... | grep -E 'gin$$|ginS$$|binding$$|render$$' | grep -v examples) TESTTAGS ?= "" .PHONY: test @@ -12,7 +12,11 @@ TESTTAGS ?= "" test: echo "mode: count" > coverage.out for d in $(TESTFOLDER); do \ - $(GO) test $(TESTTAGS) -v -covermode=count -coverprofile=profile.out $$d > tmp.out; \ + if [ -n "$(TESTTAGS)" ]; then \ + $(GO) test $(TESTTAGS) -v -covermode=count -coverprofile=profile.out $$d > tmp.out; \ + else \ + $(GO) test -v -covermode=count -coverprofile=profile.out $$d > tmp.out; \ + fi; \ cat tmp.out; \ if grep -q "^--- FAIL" tmp.out; then \ rm tmp.out; \ From 3e44fdc4d1636a2b1599c6688a76e13216a413dd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 4 Mar 2026 14:10:36 +0800 Subject: [PATCH 30/70] chore(deps): bump aquasecurity/trivy-action in the actions group (#4557) Bumps the actions group with 1 update: [aquasecurity/trivy-action](https://github.com/aquasecurity/trivy-action). Updates `aquasecurity/trivy-action` from 0.34.1 to 0.34.2 - [Release notes](https://github.com/aquasecurity/trivy-action/releases) - [Commits](https://github.com/aquasecurity/trivy-action/compare/0.34.1...0.34.2) --- updated-dependencies: - dependency-name: aquasecurity/trivy-action dependency-version: 0.34.2 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: actions ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/trivy-scan.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/trivy-scan.yml b/.github/workflows/trivy-scan.yml index a4c62bf4..73a892bd 100644 --- a/.github/workflows/trivy-scan.yml +++ b/.github/workflows/trivy-scan.yml @@ -27,7 +27,7 @@ jobs: fetch-depth: 0 - name: Run Trivy vulnerability scanner (source code) - uses: aquasecurity/trivy-action@0.34.1 + uses: aquasecurity/trivy-action@0.34.2 with: scan-type: "fs" scan-ref: "." @@ -44,7 +44,7 @@ jobs: sarif_file: "trivy-results.sarif" - name: Run Trivy scanner (table output for logs) - uses: aquasecurity/trivy-action@0.34.1 + uses: aquasecurity/trivy-action@0.34.2 if: always() with: scan-type: "fs" From d4672219fc38bd88f32da194994af8e8d718f0d8 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 13 Mar 2026 22:30:54 +0800 Subject: [PATCH 31/70] docs: reorganize doc.md TOC into thematic groups (#4579) The flat TOC under a single "API Examples" heading made it hard to scan and find relevant content. Reorganize 40+ sections into 7 logical groups (Routing, Middleware, Logging, Request Binding & Validation, Response Rendering, Server Configuration, Testing) with description lines for each group. Move scattered sections into their correct groups and fix the "avoid-loging-query-strings" anchor typo. Co-authored-by: Claude Opus 4.6 --- docs/doc.md | 1138 ++++++++++++++++++++++++++------------------------- 1 file changed, 584 insertions(+), 554 deletions(-) diff --git a/docs/doc.md b/docs/doc.md index 7201df5c..d1c33b87 100644 --- a/docs/doc.md +++ b/docs/doc.md @@ -4,8 +4,8 @@ - [Build Tags](#build-tags) - [Build with json replacement](#build-with-json-replacement) - - [Build without `MsgPack` rendering feature](#build-without-msgpack-rendering-feature) -- [API Examples](#api-examples) + - [Build without MsgPack rendering feature](#build-without-msgpack-rendering-feature) +- [Routing](#routing) - [Using GET, POST, PUT, PATCH, DELETE and OPTIONS](#using-get-post-put-patch-delete-and-options) - [Parameters in path](#parameters-in-path) - [Querystring parameters](#querystring-parameters) @@ -16,24 +16,37 @@ - [Single file](#single-file) - [Multiple files](#multiple-files) - [Grouping routes](#grouping-routes) + - [Redirects](#redirects) +- [Middleware](#middleware) - [Blank Gin without middleware by default](#blank-gin-without-middleware-by-default) - [Using middleware](#using-middleware) + - [Custom Middleware](#custom-middleware) - [Custom Recovery behavior](#custom-recovery-behavior) + - [Using BasicAuth() middleware](#using-basicauth-middleware) + - [Goroutines inside a middleware](#goroutines-inside-a-middleware) +- [Logging](#logging) - [How to write log file](#how-to-write-log-file) - [Custom Log Format](#custom-log-format) + - [Skip logging](#skip-logging) - [Controlling Log output coloring](#controlling-log-output-coloring) - - [Avoid logging query strings](#avoid-loging-query-strings) + - [Avoid logging query strings](#avoid-logging-query-strings) + - [Define format for the log of routes](#define-format-for-the-log-of-routes) +- [Request Binding & Validation](#request-binding--validation) - [Model binding and validation](#model-binding-and-validation) - [Custom Validators](#custom-validators) - [Only Bind Query String](#only-bind-query-string) - [Bind Query String or Post Data](#bind-query-string-or-post-data) - [Bind default value if none provided](#bind-default-value-if-none-provided) - - [Collection format for arrays](#collection-format-for-arrays) + - [Collection format for arrays](#collection-format-for-arrays) - [Bind Uri](#bind-uri) - [Bind custom unmarshaler](#bind-custom-unmarshaler) - [Bind Header](#bind-header) - [Bind HTML checkboxes](#bind-html-checkboxes) - [Multipart/Urlencoded binding](#multiparturlencoded-binding) + - [Bind form-data request with custom struct](#bind-form-data-request-with-custom-struct) + - [Try to bind body into different structs](#try-to-bind-body-into-different-structs) + - [Bind form-data request with custom struct and custom tag](#bind-form-data-request-with-custom-struct-and-custom-tag) +- [Response Rendering](#response-rendering) - [XML, JSON, YAML, TOML and ProtoBuf rendering](#xml-json-yaml-toml-and-protobuf-rendering) - [SecureJSON](#securejson) - [JSONP](#jsonp) @@ -47,27 +60,22 @@ - [Custom Delimiters](#custom-delimiters) - [Custom Template Funcs](#custom-template-funcs) - [Multitemplate](#multitemplate) - - [Redirects](#redirects) - - [Custom Middleware](#custom-middleware) - - [Using BasicAuth() middleware](#using-basicauth-middleware) - - [Goroutines inside a middleware](#goroutines-inside-a-middleware) + - [Build a single binary with templates](#build-a-single-binary-with-templates) +- [Server Configuration](#server-configuration) - [Custom HTTP configuration](#custom-http-configuration) + - [Custom json codec at runtime](#custom-json-codec-at-runtime) - [Support Let's Encrypt](#support-lets-encrypt) - [Run multiple service using Gin](#run-multiple-service-using-gin) - [Graceful shutdown or restart](#graceful-shutdown-or-restart) - [Third-party packages](#third-party-packages) - [Manually](#manually) - - [Build a single binary with templates](#build-a-single-binary-with-templates) - - [Bind form-data request with custom struct](#bind-form-data-request-with-custom-struct) - - [Try to bind body into different structs](#try-to-bind-body-into-different-structs) - - [Bind form-data request with custom struct and custom tag](#bind-form-data-request-with-custom-struct-and-custom-tag) - [http2 server push](#http2-server-push) - - [Define format for the log of routes](#define-format-for-the-log-of-routes) - [Set and get a cookie](#set-and-get-a-cookie) - - [Custom json codec at runtime](#custom-json-codec-at-runtime) -- [Don't trust all proxies](#dont-trust-all-proxies) + - [Don't trust all proxies](#dont-trust-all-proxies) - [Testing](#testing) +You can find a number of ready-to-run examples at [Gin examples repository](https://github.com/gin-gonic/examples). + ## Build tags ### Build with json replacement @@ -89,7 +97,7 @@ go build -tags=go_json . [sonic](https://github.com/bytedance/sonic) ```sh -$ go build -tags=sonic . +go build -tags=sonic . ``` ### Build without `MsgPack` rendering feature @@ -102,9 +110,9 @@ go build -tags=nomsgpack . This is useful to reduce the binary size of executable files. See the [detail information](https://github.com/gin-gonic/gin/pull/1852). -## API Examples +## Routing -You can find a number of ready-to-run examples at [Gin examples repository](https://github.com/gin-gonic/examples). +> Learn how to define routes, handle parameters, and organize endpoints. ### Using GET, POST, PUT, PATCH, DELETE and OPTIONS @@ -361,6 +369,40 @@ func main() { } ``` +### Redirects + +Issuing a HTTP redirect is easy. Both internal and external locations are supported. + +```go +r.GET("/test", func(c *gin.Context) { + c.Redirect(http.StatusMovedPermanently, "http://www.google.com/") +}) +``` + +Issuing a HTTP redirect from POST. Refer to issue: [#444](https://github.com/gin-gonic/gin/issues/444) + +```go +r.POST("/test", func(c *gin.Context) { + c.Redirect(http.StatusFound, "/foo") +}) +``` + +Issuing a Router redirect, use `HandleContext` like below. + +```go +r.GET("/test", func(c *gin.Context) { + c.Request.URL.Path = "/test2" + r.HandleContext(c) +}) +r.GET("/test2", func(c *gin.Context) { + c.JSON(http.StatusOK, gin.H{"hello": "world"}) +}) +``` + +## Middleware + +> Configure middleware for request processing, authentication, and error recovery. + ### Blank Gin without middleware by default Use @@ -417,6 +459,46 @@ func main() { } ``` +### Custom Middleware + +```go +func Logger() gin.HandlerFunc { + return func(c *gin.Context) { + t := time.Now() + + // Set example variable + c.Set("example", "12345") + + // before request + + c.Next() + + // after request + latency := time.Since(t) + log.Print(latency) + + // access the status we are sending + status := c.Writer.Status() + log.Println(status) + } +} + +func main() { + r := gin.New() + r.Use(Logger()) + + r.GET("/test", func(c *gin.Context) { + example := c.MustGet("example").(string) + + // it would print: "12345" + log.Println(example) + }) + + // Listen and serve on 0.0.0.0:8080 + r.Run(":8080") +} +``` + ### Custom Recovery behavior ```go @@ -451,6 +533,82 @@ func main() { } ``` +### Using BasicAuth() middleware + +```go +// simulate some private data +var secrets = gin.H{ + "foo": gin.H{"email": "foo@bar.com", "phone": "123433"}, + "austin": gin.H{"email": "austin@example.com", "phone": "666"}, + "lena": gin.H{"email": "lena@guapa.com", "phone": "523443"}, +} + +func main() { + r := gin.Default() + + // Group using gin.BasicAuth() middleware + // gin.Accounts is a shortcut for map[string]string + authorized := r.Group("/admin", gin.BasicAuth(gin.Accounts{ + "foo": "bar", + "austin": "1234", + "lena": "hello2", + "manu": "4321", + })) + + // /admin/secrets endpoint + // hit "localhost:8080/admin/secrets + authorized.GET("/secrets", func(c *gin.Context) { + // get user, it was set by the BasicAuth middleware + user := c.MustGet(gin.AuthUserKey).(string) + if secret, ok := secrets[user]; ok { + c.JSON(http.StatusOK, gin.H{"user": user, "secret": secret}) + } else { + c.JSON(http.StatusOK, gin.H{"user": user, "secret": "NO SECRET :("}) + } + }) + + // Listen and serve on 0.0.0.0:8080 + r.Run(":8080") +} +``` + +### Goroutines inside a middleware + +When starting new Goroutines inside a middleware or handler, you **SHOULD NOT** use the original context inside it, you have to use a read-only copy. + +```go +func main() { + r := gin.Default() + + r.GET("/long_async", func(c *gin.Context) { + // create copy to be used inside the goroutine + cCp := c.Copy() + go func() { + // simulate a long task with time.Sleep(). 5 seconds + time.Sleep(5 * time.Second) + + // note that you are using the copied context "cCp", IMPORTANT + log.Println("Done! in path " + cCp.Request.URL.Path) + }() + }) + + r.GET("/long_sync", func(c *gin.Context) { + // simulate a long task with time.Sleep(). 5 seconds + time.Sleep(5 * time.Second) + + // since we are NOT using a goroutine, we do not have to copy the context + log.Println("Done! in path " + c.Request.URL.Path) + }) + + // Listen and serve on 0.0.0.0:8080 + r.Run(":8080") +} +``` + +## Logging + +> Control log output, formatting, and filtering. + ### How to write log file ```go @@ -470,7 +628,7 @@ func main() { c.String(http.StatusOK, "pong") }) -   router.Run(":8080") + router.Run(":8080") } ``` @@ -598,15 +756,63 @@ func main() { ```go func main() { router := gin.New() - + // SkipQueryString indicates that the logger should not log the query string. // For example, /path?q=1 will be logged as /path loggerConfig := gin.LoggerConfig{SkipQueryString: true} - + router.Use(gin.LoggerWithConfig(loggerConfig)) } ``` +### Define format for the log of routes + +The default log of routes is: + +```sh +[GIN-debug] POST /foo --> main.main.func1 (3 handlers) +[GIN-debug] GET /bar --> main.main.func2 (3 handlers) +[GIN-debug] GET /status --> main.main.func3 (3 handlers) +``` + +If you want to log this information in given format (e.g. JSON, key values or something else), then you can define this format with `gin.DebugPrintRouteFunc`. +In the example below, we log all routes with standard log package but you can use another log tools that suits of your needs. + +```go +import ( + "log" + "net/http" + + "github.com/gin-gonic/gin" +) + +func main() { + r := gin.Default() + gin.DebugPrintRouteFunc = func(httpMethod, absolutePath, handlerName string, nuHandlers int) { + log.Printf("endpoint %v %v %v %v\n", httpMethod, absolutePath, handlerName, nuHandlers) + } + + r.POST("/foo", func(c *gin.Context) { + c.JSON(http.StatusOK, "foo") + }) + + r.GET("/bar", func(c *gin.Context) { + c.JSON(http.StatusOK, "bar") + }) + + r.GET("/status", func(c *gin.Context) { + c.JSON(http.StatusOK, "ok") + }) + + // Listen and Server in http://0.0.0.0:8080 + r.Run() +} +``` + +## Request Binding & Validation + +> Bind and validate request data from query strings, forms, JSON, and more. + ### Model binding and validation To bind a request body into a type, use model binding. We currently support binding of JSON, XML, YAML, TOML and standard form values (foo=bar&boo=baz). @@ -883,7 +1089,6 @@ Test it with: curl -X GET "localhost:8085/testing?name=appleboy&address=xyz&birthday=1992-03-15&createTime=1562400033000000123&unixTime=1562400033&unixMilliTime=1562400033001&unixMicroTime=1562400033000012" ``` - ### Bind default value if none provided If the server should bind a default value to a field when the client does not provide one, specify the default value using the `default` key within the `form` tag: @@ -892,44 +1097,44 @@ If the server should bind a default value to a field when the client does not pr package main import ( - "net/http" + "net/http" - "github.com/gin-gonic/gin" + "github.com/gin-gonic/gin" ) type Person struct { - Name string `form:"name,default=William"` - Age int `form:"age,default=10"` - Friends []string `form:"friends,default=Will;Bill"` - Addresses [2]string `form:"addresses,default=foo bar" collection_format:"ssv"` - LapTimes []int `form:"lap_times,default=1;2;3" collection_format:"csv"` + Name string `form:"name,default=William"` + Age int `form:"age,default=10"` + Friends []string `form:"friends,default=Will;Bill"` + Addresses [2]string `form:"addresses,default=foo bar" collection_format:"ssv"` + LapTimes []int `form:"lap_times,default=1;2;3" collection_format:"csv"` } func main() { - g := gin.Default() - g.POST("/person", func(c *gin.Context) { - var req Person - if err := c.ShouldBindQuery(&req); err != nil { - c.JSON(http.StatusBadRequest, err) - return - } - c.JSON(http.StatusOK, req) - }) - _ = g.Run("localhost:8080") + g := gin.Default() + g.POST("/person", func(c *gin.Context) { + var req Person + if err := c.ShouldBindQuery(&req); err != nil { + c.JSON(http.StatusBadRequest, err) + return + } + c.JSON(http.StatusOK, req) + }) + _ = g.Run("localhost:8080") } ``` -``` +```sh curl -X POST http://localhost:8080/person {"Name":"William","Age":10,"Friends":["Will","Bill"],"Colors":["red","blue"],"LapTimes":[1,2,3]} ``` NOTE: For default [collection values](#collection-format-for-arrays), the following rules apply: + - Since commas are used to delimit tag options, they are not supported within a default value and will result in undefined behavior - For the collection formats "multi" and "csv", a semicolon should be used in place of a comma to delimit default values - Since semicolons are used to delimit default values for "multi" and "csv", they are not supported within a default value for "multi" and "csv" - #### Collection format for arrays | Format | Description | Example | @@ -944,29 +1149,29 @@ NOTE: For default [collection values](#collection-format-for-arrays), the follow package main import ( - "log" - "time" - "github.com/gin-gonic/gin" + "log" + "time" + "github.com/gin-gonic/gin" ) type Person struct { - Name string `form:"name"` - Addresses []string `form:"addresses" collection_format:"csv"` - Birthday time.Time `form:"birthday" time_format:"2006-01-02" time_utc:"1"` - CreateTime time.Time `form:"createTime" time_format:"unixNano"` - UnixTime time.Time `form:"unixTime" time_format:"unix"` + Name string `form:"name"` + Addresses []string `form:"addresses" collection_format:"csv"` + Birthday time.Time `form:"birthday" time_format:"2006-01-02" time_utc:"1"` + CreateTime time.Time `form:"createTime" time_format:"unixNano"` + UnixTime time.Time `form:"unixTime" time_format:"unix"` } func main() { - route := gin.Default() - route.GET("/testing", startPage) - route.Run(":8085") + route := gin.Default() + route.GET("/testing", startPage) + route.Run(":8085") } func startPage(c *gin.Context) { - var person Person - // If `GET`, only `Form` binding engine (`query`) used. - // If `POST`, first checks the `content-type` for `JSON` or `XML`, then uses `Form` (`form-data`). - // See more at https://github.com/gin-gonic/gin/blob/master/binding/binding.go#L48 + var person Person + // If `GET`, only `Form` binding engine (`query`) used. + // If `POST`, first checks the `content-type` for `JSON` or `XML`, then uses `Form` (`form-data`). + // See more at https://github.com/gin-gonic/gin/blob/master/binding/binding.go#L48 if c.ShouldBind(&person) == nil { log.Println(person.Name) log.Println(person.Addresses) @@ -974,13 +1179,14 @@ func startPage(c *gin.Context) { log.Println(person.CreateTime) log.Println(person.UnixTime) } - c.String(200, "Success") + c.String(200, "Success") } ``` Test it with: + ```sh -$ curl -X GET "localhost:8085/testing?name=appleboy&addresses=foo,bar&birthday=1992-03-15&createTime=1562400033000000123&unixTime=1562400033" +curl -X GET "localhost:8085/testing?name=appleboy&addresses=foo,bar&birthday=1992-03-15&createTime=1562400033000000123&unixTime=1562400033" ``` ### Bind Uri @@ -1065,12 +1271,15 @@ Test it with: ```sh curl 'localhost:8088/test?birthday=2000-01-01&birthdays=2000-01-01,2000-01-02' ``` + Result + ```sh {"Birthday":"2000/01/01","Birthdays":["2000/01/01","2000/01/02"],"BirthdaysDefault":["2020/09/01","2020/09/02"]} ``` Note: + - If `parser=encoding.TextUnmarshaler` is specified for a type that does **not** implement `encoding.TextUnmarshaler`, gin will ignore it and proceed with its default binding logic. - If `parser=encoding.TextUnmarshaler` is specified for a type and that type's implementation of `encoding.TextUnmarshaler` returns an error, gin will stop binding and return the error to the client. @@ -1117,12 +1326,15 @@ Test it with: ```sh curl 'localhost:8088/test?birthday=2000-01-01&birthdays=2000-01-01,2000-01-02' ``` + Result + ```sh {"Birthday":"2000/01/01","Birthdays":["2000/01/01","2000/01/02"],"BirthdaysDefault":["2020/09/01","2020/09/02"]} ``` Note: + - If a type implements both `encoding.TextUnmarshaler` and `BindUnmarshaler`, gin will use `BindUnmarshaler` by default unless you specify `parser=encoding.TextUnmarshaler` in the binding tag. - If a type returns an error from its implementation of `BindUnmarshaler`, gin will stop binding and return the error to the client. @@ -1194,21 +1406,21 @@ form.html ```html
-

Check some colors

- - - - - - - +

Check some colors

+ + + + + + +
``` result: ```json -{"color":["red","green","blue"]} +{ "color": ["red", "green", "blue"] } ``` ### Multipart/Urlencoded binding @@ -1255,6 +1467,202 @@ Test it with: curl -X POST -v --form name=user --form "avatar=@./avatar.png" http://localhost:8080/profile ``` +### Bind form-data request with custom struct + +The follow example using custom struct: + +```go +type StructA struct { + FieldA string `form:"field_a"` +} + +type StructB struct { + NestedStruct StructA + FieldB string `form:"field_b"` +} + +type StructC struct { + NestedStructPointer *StructA + FieldC string `form:"field_c"` +} + +type StructD struct { + NestedAnonyStruct struct { + FieldX string `form:"field_x"` + } + FieldD string `form:"field_d"` +} + +func GetDataB(c *gin.Context) { + var b StructB + c.Bind(&b) + c.JSON(http.StatusOK, gin.H{ + "a": b.NestedStruct, + "b": b.FieldB, + }) +} + +func GetDataC(c *gin.Context) { + var b StructC + c.Bind(&b) + c.JSON(http.StatusOK, gin.H{ + "a": b.NestedStructPointer, + "c": b.FieldC, + }) +} + +func GetDataD(c *gin.Context) { + var b StructD + c.Bind(&b) + c.JSON(http.StatusOK, gin.H{ + "x": b.NestedAnonyStruct, + "d": b.FieldD, + }) +} + +func main() { + r := gin.Default() + r.GET("/getb", GetDataB) + r.GET("/getc", GetDataC) + r.GET("/getd", GetDataD) + + r.Run() +} +``` + +Using the command `curl` command result: + +```sh +$ curl "http://localhost:8080/getb?field_a=hello&field_b=world" +{"a":{"FieldA":"hello"},"b":"world"} +$ curl "http://localhost:8080/getc?field_a=hello&field_c=world" +{"a":{"FieldA":"hello"},"c":"world"} +$ curl "http://localhost:8080/getd?field_x=hello&field_d=world" +{"d":"world","x":{"FieldX":"hello"}} +``` + +### Try to bind body into different structs + +The normal methods for binding request body consumes `c.Request.Body` and they +cannot be called multiple times. + +```go +type formA struct { + Foo string `json:"foo" xml:"foo" binding:"required"` +} + +type formB struct { + Bar string `json:"bar" xml:"bar" binding:"required"` +} + +func SomeHandler(c *gin.Context) { + objA := formA{} + objB := formB{} + // Calling c.ShouldBind consumes c.Request.Body and it cannot be reused. + if errA := c.ShouldBind(&objA); errA == nil { + c.String(http.StatusOK, `the body should be formA`) + // Always an error is occurred by this because c.Request.Body is EOF now. + } else if errB := c.ShouldBind(&objB); errB == nil { + c.String(http.StatusOK, `the body should be formB`) + } else { + ... + } +} +``` + +For this, you can use `c.ShouldBindBodyWith` or shortcuts. + +- `c.ShouldBindBodyWithJSON` is a shortcut for c.ShouldBindBodyWith(obj, binding.JSON). +- `c.ShouldBindBodyWithXML` is a shortcut for c.ShouldBindBodyWith(obj, binding.XML). +- `c.ShouldBindBodyWithYAML` is a shortcut for c.ShouldBindBodyWith(obj, binding.YAML). +- `c.ShouldBindBodyWithTOML` is a shortcut for c.ShouldBindBodyWith(obj, binding.TOML). + +```go +func SomeHandler(c *gin.Context) { + objA := formA{} + objB := formB{} + // This reads c.Request.Body and stores the result into the context. + if errA := c.ShouldBindBodyWith(&objA, binding.Form); errA == nil { + c.String(http.StatusOK, `the body should be formA`) + // At this time, it reuses body stored in the context. + } else if errB := c.ShouldBindBodyWith(&objB, binding.JSON); errB == nil { + c.String(http.StatusOK, `the body should be formB JSON`) + // And it can accepts other formats + } else if errB2 := c.ShouldBindBodyWithXML(&objB); errB2 == nil { + c.String(http.StatusOK, `the body should be formB XML`) + } else { + ... + } +} +``` + +1. `c.ShouldBindBodyWith` stores body into the context before binding. This has + a slight impact to performance, so you should not use this method if you are + enough to call binding at once. +2. This feature is only needed for some formats -- `JSON`, `XML`, `MsgPack`, + `ProtoBuf`. For other formats, `Query`, `Form`, `FormPost`, `FormMultipart`, + can be called by `c.ShouldBind()` multiple times without any damage to + performance (See [#1341](https://github.com/gin-gonic/gin/pull/1341)). + +### Bind form-data request with custom struct and custom tag + +```go +const ( + customerTag = "url" + defaultMemory = 32 << 20 +) + +type customerBinding struct {} + +func (customerBinding) Name() string { + return "form" +} + +func (customerBinding) Bind(req *http.Request, obj any) error { + if err := req.ParseForm(); err != nil { + return err + } + if err := req.ParseMultipartForm(defaultMemory); err != nil { + if err != http.ErrNotMultipart { + return err + } + } + if err := binding.MapFormWithTag(obj, req.Form, customerTag); err != nil { + return err + } + return validate(obj) +} + +func validate(obj any) error { + if binding.Validator == nil { + return nil + } + return binding.Validator.ValidateStruct(obj) +} + +// Now we can do this!!! +// FormA is an external type that we can't modify it's tag +type FormA struct { + FieldA string `url:"field_a"` +} + +func ListHandler(s *Service) func(ctx *gin.Context) { + return func(ctx *gin.Context) { + var urlBinding = customerBinding{} + var opt FormA + err := ctx.MustBindWith(&opt, urlBinding) + if err != nil { + ... + } + ... + } +} +``` + +## Response Rendering + +> Render responses in various formats including JSON, XML, HTML, and more. + ### XML, JSON, YAML, TOML and ProtoBuf rendering ```go @@ -1499,9 +1907,7 @@ templates/index.tmpl ```html -

- {{ .title }} -

+

{{ .title }}

``` @@ -1529,10 +1935,9 @@ templates/posts/index.tmpl ```html {{ define "posts/index.tmpl" }} -

- {{ .title }} -

-

Using posts/index.tmpl

+ +

{{ .title }}

+

Using posts/index.tmpl

{{ end }} ``` @@ -1541,10 +1946,9 @@ templates/users/index.tmpl ```html {{ define "users/index.tmpl" }} -

- {{ .title }} -

-

Using users/index.tmpl

+ +

{{ .title }}

+

Using users/index.tmpl

{{ end }} ``` @@ -1630,147 +2034,62 @@ Date: 2017/07/01 Gin allows only one html.Template by default. Check [a multitemplate render](https://github.com/gin-contrib/multitemplate) for using features like go 1.6 `block template`. -### Redirects +### Build a single binary with templates -Issuing a HTTP redirect is easy. Both internal and external locations are supported. +You can build a server into a single binary containing templates by using the [embed](https://pkg.go.dev/embed) package. ```go -r.GET("/test", func(c *gin.Context) { - c.Redirect(http.StatusMovedPermanently, "http://www.google.com/") -}) -``` +package main -Issuing a HTTP redirect from POST. Refer to issue: [#444](https://github.com/gin-gonic/gin/issues/444) +import ( + "embed" + "html/template" + "net/http" -```go -r.POST("/test", func(c *gin.Context) { - c.Redirect(http.StatusFound, "/foo") -}) -``` + "github.com/gin-gonic/gin" +) -Issuing a Router redirect, use `HandleContext` like below. - -``` go -r.GET("/test", func(c *gin.Context) { - c.Request.URL.Path = "/test2" - r.HandleContext(c) -}) -r.GET("/test2", func(c *gin.Context) { - c.JSON(http.StatusOK, gin.H{"hello": "world"}) -}) -``` - -### Custom Middleware - -```go -func Logger() gin.HandlerFunc { - return func(c *gin.Context) { - t := time.Now() - - // Set example variable - c.Set("example", "12345") - - // before request - - c.Next() - - // after request - latency := time.Since(t) - log.Print(latency) - - // access the status we are sending - status := c.Writer.Status() - log.Println(status) - } -} +//go:embed assets/* templates/* +var f embed.FS func main() { - r := gin.New() - r.Use(Logger()) + router := gin.Default() + templ := template.Must(template.New("").ParseFS(f, "templates/*.tmpl", "templates/foo/*.tmpl")) + router.SetHTMLTemplate(templ) - r.GET("/test", func(c *gin.Context) { - example := c.MustGet("example").(string) + // example: /public/assets/images/example.png + router.StaticFS("/public", http.FS(f)) - // it would print: "12345" - log.Println(example) + router.GET("/", func(c *gin.Context) { + c.HTML(http.StatusOK, "index.tmpl", gin.H{ + "title": "Main website", + }) }) - // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.GET("/foo", func(c *gin.Context) { + c.HTML(http.StatusOK, "bar.tmpl", gin.H{ + "title": "Foo website", + }) + }) + + router.GET("favicon.ico", func(c *gin.Context) { + file, _ := f.ReadFile("assets/favicon.ico") + c.Data( + http.StatusOK, + "image/x-icon", + file, + ) + }) + + router.Run(":8080") } ``` -### Using BasicAuth() middleware +See a complete example in the `https://github.com/gin-gonic/examples/tree/master/assets-in-binary/example02` directory. -```go -// simulate some private data -var secrets = gin.H{ - "foo": gin.H{"email": "foo@bar.com", "phone": "123433"}, - "austin": gin.H{"email": "austin@example.com", "phone": "666"}, - "lena": gin.H{"email": "lena@guapa.com", "phone": "523443"}, -} +## Server Configuration -func main() { - r := gin.Default() - - // Group using gin.BasicAuth() middleware - // gin.Accounts is a shortcut for map[string]string - authorized := r.Group("/admin", gin.BasicAuth(gin.Accounts{ - "foo": "bar", - "austin": "1234", - "lena": "hello2", - "manu": "4321", - })) - - // /admin/secrets endpoint - // hit "localhost:8080/admin/secrets - authorized.GET("/secrets", func(c *gin.Context) { - // get user, it was set by the BasicAuth middleware - user := c.MustGet(gin.AuthUserKey).(string) - if secret, ok := secrets[user]; ok { - c.JSON(http.StatusOK, gin.H{"user": user, "secret": secret}) - } else { - c.JSON(http.StatusOK, gin.H{"user": user, "secret": "NO SECRET :("}) - } - }) - - // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") -} -``` - -### Goroutines inside a middleware - -When starting new Goroutines inside a middleware or handler, you **SHOULD NOT** use the original context inside it, you have to use a read-only copy. - -```go -func main() { - r := gin.Default() - - r.GET("/long_async", func(c *gin.Context) { - // create copy to be used inside the goroutine - cCp := c.Copy() - go func() { - // simulate a long task with time.Sleep(). 5 seconds - time.Sleep(5 * time.Second) - - // note that you are using the copied context "cCp", IMPORTANT - log.Println("Done! in path " + cCp.Request.URL.Path) - }() - }) - - r.GET("/long_sync", func(c *gin.Context) { - // simulate a long task with time.Sleep(). 5 seconds - time.Sleep(5 * time.Second) - - // since we are NOT using a goroutine, we do not have to copy the context - log.Println("Done! in path " + c.Request.URL.Path) - }) - - // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") -} -``` +> Configure HTTP servers, TLS, proxies, and runtime settings. ### Custom HTTP configuration @@ -1800,6 +2119,65 @@ func main() { } ``` +### Custom json codec at runtime + +Gin support custom json serialization and deserialization logic without using compile tags. + +1. Define a custom struct implements the `json.Core` interface. + +2. Before your engine starts, assign values to `json.API` using the custom struct. + +```go +package main + +import ( + "io" + + "github.com/gin-gonic/gin" + "github.com/gin-gonic/gin/codec/json" + jsoniter "github.com/json-iterator/go" +) + +var customConfig = jsoniter.Config{ + EscapeHTML: true, + SortMapKeys: true, + ValidateJsonRawMessage: true, +}.Froze() + +// implement api.JsonApi +type customJsonApi struct { +} + +func (j customJsonApi) Marshal(v any) ([]byte, error) { + return customConfig.Marshal(v) +} + +func (j customJsonApi) Unmarshal(data []byte, v any) error { + return customConfig.Unmarshal(data, v) +} + +func (j customJsonApi) MarshalIndent(v any, prefix, indent string) ([]byte, error) { + return customConfig.MarshalIndent(v, prefix, indent) +} + +func (j customJsonApi) NewEncoder(writer io.Writer) json.Encoder { + return customConfig.NewEncoder(writer) +} + +func (j customJsonApi) NewDecoder(reader io.Reader) json.Decoder { + return customConfig.NewDecoder(reader) +} + +func main() { + //Replace the default json api + json.API = customJsonApi{} + + //Start your gin engine + router := gin.Default() + router.Run(":8080") +} +``` + ### Support Let's Encrypt example for 1-line LetsEncrypt HTTPS servers. @@ -1965,9 +2343,9 @@ endless.ListenAndServe(":4242", router) Alternatives: -* [grace](https://github.com/facebookgo/grace): Graceful restart & zero downtime deploy for Go servers. -* [graceful](https://github.com/tylerb/graceful): Graceful is a Go package enabling graceful shutdown of an http.Handler server. -* [manners](https://github.com/braintree/manners): A polite Go HTTP server that shuts down gracefully. +- [grace](https://github.com/facebookgo/grace): Graceful restart & zero downtime deploy for Go servers. +- [graceful](https://github.com/tylerb/graceful): Graceful is a Go package enabling graceful shutdown of an http.Handler server. +- [manners](https://github.com/braintree/manners): A polite Go HTTP server that shuts down gracefully. #### Manually @@ -2033,251 +2411,6 @@ func main() { } ``` -### Build a single binary with templates - -You can build a server into a single binary containing templates by using the [embed](https://pkg.go.dev/embed) package. - -```go -package main - -import ( - "embed" - "html/template" - "net/http" - - "github.com/gin-gonic/gin" -) - -//go:embed assets/* templates/* -var f embed.FS - -func main() { - router := gin.Default() - templ := template.Must(template.New("").ParseFS(f, "templates/*.tmpl", "templates/foo/*.tmpl")) - router.SetHTMLTemplate(templ) - - // example: /public/assets/images/example.png - router.StaticFS("/public", http.FS(f)) - - router.GET("/", func(c *gin.Context) { - c.HTML(http.StatusOK, "index.tmpl", gin.H{ - "title": "Main website", - }) - }) - - router.GET("/foo", func(c *gin.Context) { - c.HTML(http.StatusOK, "bar.tmpl", gin.H{ - "title": "Foo website", - }) - }) - - router.GET("favicon.ico", func(c *gin.Context) { - file, _ := f.ReadFile("assets/favicon.ico") - c.Data( - http.StatusOK, - "image/x-icon", - file, - ) - }) - - router.Run(":8080") -} -``` - -See a complete example in the `https://github.com/gin-gonic/examples/tree/master/assets-in-binary/example02` directory. - -### Bind form-data request with custom struct - -The follow example using custom struct: - -```go -type StructA struct { - FieldA string `form:"field_a"` -} - -type StructB struct { - NestedStruct StructA - FieldB string `form:"field_b"` -} - -type StructC struct { - NestedStructPointer *StructA - FieldC string `form:"field_c"` -} - -type StructD struct { - NestedAnonyStruct struct { - FieldX string `form:"field_x"` - } - FieldD string `form:"field_d"` -} - -func GetDataB(c *gin.Context) { - var b StructB - c.Bind(&b) - c.JSON(http.StatusOK, gin.H{ - "a": b.NestedStruct, - "b": b.FieldB, - }) -} - -func GetDataC(c *gin.Context) { - var b StructC - c.Bind(&b) - c.JSON(http.StatusOK, gin.H{ - "a": b.NestedStructPointer, - "c": b.FieldC, - }) -} - -func GetDataD(c *gin.Context) { - var b StructD - c.Bind(&b) - c.JSON(http.StatusOK, gin.H{ - "x": b.NestedAnonyStruct, - "d": b.FieldD, - }) -} - -func main() { - r := gin.Default() - r.GET("/getb", GetDataB) - r.GET("/getc", GetDataC) - r.GET("/getd", GetDataD) - - r.Run() -} -``` - -Using the command `curl` command result: - -```sh -$ curl "http://localhost:8080/getb?field_a=hello&field_b=world" -{"a":{"FieldA":"hello"},"b":"world"} -$ curl "http://localhost:8080/getc?field_a=hello&field_c=world" -{"a":{"FieldA":"hello"},"c":"world"} -$ curl "http://localhost:8080/getd?field_x=hello&field_d=world" -{"d":"world","x":{"FieldX":"hello"}} -``` - -### Try to bind body into different structs - -The normal methods for binding request body consumes `c.Request.Body` and they -cannot be called multiple times. - -```go -type formA struct { - Foo string `json:"foo" xml:"foo" binding:"required"` -} - -type formB struct { - Bar string `json:"bar" xml:"bar" binding:"required"` -} - -func SomeHandler(c *gin.Context) { - objA := formA{} - objB := formB{} - // Calling c.ShouldBind consumes c.Request.Body and it cannot be reused. - if errA := c.ShouldBind(&objA); errA == nil { - c.String(http.StatusOK, `the body should be formA`) - // Always an error is occurred by this because c.Request.Body is EOF now. - } else if errB := c.ShouldBind(&objB); errB == nil { - c.String(http.StatusOK, `the body should be formB`) - } else { - ... - } -} -``` - -For this, you can use `c.ShouldBindBodyWith` or shortcuts. - -- `c.ShouldBindBodyWithJSON` is a shortcut for c.ShouldBindBodyWith(obj, binding.JSON). -- `c.ShouldBindBodyWithXML` is a shortcut for c.ShouldBindBodyWith(obj, binding.XML). -- `c.ShouldBindBodyWithYAML` is a shortcut for c.ShouldBindBodyWith(obj, binding.YAML). -- `c.ShouldBindBodyWithTOML` is a shortcut for c.ShouldBindBodyWith(obj, binding.TOML). - -```go -func SomeHandler(c *gin.Context) { - objA := formA{} - objB := formB{} - // This reads c.Request.Body and stores the result into the context. - if errA := c.ShouldBindBodyWith(&objA, binding.Form); errA == nil { - c.String(http.StatusOK, `the body should be formA`) - // At this time, it reuses body stored in the context. - } else if errB := c.ShouldBindBodyWith(&objB, binding.JSON); errB == nil { - c.String(http.StatusOK, `the body should be formB JSON`) - // And it can accepts other formats - } else if errB2 := c.ShouldBindBodyWithXML(&objB); errB2 == nil { - c.String(http.StatusOK, `the body should be formB XML`) - } else { - ... - } -} -``` - -1. `c.ShouldBindBodyWith` stores body into the context before binding. This has -a slight impact to performance, so you should not use this method if you are -enough to call binding at once. -2. This feature is only needed for some formats -- `JSON`, `XML`, `MsgPack`, -`ProtoBuf`. For other formats, `Query`, `Form`, `FormPost`, `FormMultipart`, -can be called by `c.ShouldBind()` multiple times without any damage to -performance (See [#1341](https://github.com/gin-gonic/gin/pull/1341)). - -### Bind form-data request with custom struct and custom tag - -```go -const ( - customerTag = "url" - defaultMemory = 32 << 20 -) - -type customerBinding struct {} - -func (customerBinding) Name() string { - return "form" -} - -func (customerBinding) Bind(req *http.Request, obj any) error { - if err := req.ParseForm(); err != nil { - return err - } - if err := req.ParseMultipartForm(defaultMemory); err != nil { - if err != http.ErrNotMultipart { - return err - } - } - if err := binding.MapFormWithTag(obj, req.Form, customerTag); err != nil { - return err - } - return validate(obj) -} - -func validate(obj any) error { - if binding.Validator == nil { - return nil - } - return binding.Validator.ValidateStruct(obj) -} - -// Now we can do this!!! -// FormA is an external type that we can't modify it's tag -type FormA struct { - FieldA string `url:"field_a"` -} - -func ListHandler(s *Service) func(ctx *gin.Context) { - return func(ctx *gin.Context) { - var urlBinding = customerBinding{} - var opt FormA - err := ctx.MustBindWith(&opt, urlBinding) - if err != nil { - ... - } - ... - } -} -``` - ### http2 server push http.Pusher is supported only **go1.8+**. See the [golang blog](https://go.dev/blog/h2push) for detail information. @@ -2327,50 +2460,6 @@ func main() { } ``` -### Define format for the log of routes - -The default log of routes is: - -```sh -[GIN-debug] POST /foo --> main.main.func1 (3 handlers) -[GIN-debug] GET /bar --> main.main.func2 (3 handlers) -[GIN-debug] GET /status --> main.main.func3 (3 handlers) -``` - -If you want to log this information in given format (e.g. JSON, key values or something else), then you can define this format with `gin.DebugPrintRouteFunc`. -In the example below, we log all routes with standard log package but you can use another log tools that suits of your needs. - -```go -import ( - "log" - "net/http" - - "github.com/gin-gonic/gin" -) - -func main() { - r := gin.Default() - gin.DebugPrintRouteFunc = func(httpMethod, absolutePath, handlerName string, nuHandlers int) { - log.Printf("endpoint %v %v %v %v\n", httpMethod, absolutePath, handlerName, nuHandlers) - } - - r.POST("/foo", func(c *gin.Context) { - c.JSON(http.StatusOK, "foo") - }) - - r.GET("/bar", func(c *gin.Context) { - c.JSON(http.StatusOK, "bar") - }) - - r.GET("/status", func(c *gin.Context) { - c.JSON(http.StatusOK, "ok") - }) - - // Listen and Server in http://0.0.0.0:8080 - r.Run() -} -``` - ### Set and get a cookie ```go @@ -2451,66 +2540,7 @@ func main() { } ``` -### Custom json codec at runtime - -Gin support custom json serialization and deserialization logic without using compile tags. - -1. Define a custom struct implements the `json.Core` interface. - -2. Before your engine starts, assign values to `json.API` using the custom struct. - -```go -package main - -import ( - "io" - - "github.com/gin-gonic/gin" - "github.com/gin-gonic/gin/codec/json" - jsoniter "github.com/json-iterator/go" -) - -var customConfig = jsoniter.Config{ - EscapeHTML: true, - SortMapKeys: true, - ValidateJsonRawMessage: true, -}.Froze() - -// implement api.JsonApi -type customJsonApi struct { -} - -func (j customJsonApi) Marshal(v any) ([]byte, error) { - return customConfig.Marshal(v) -} - -func (j customJsonApi) Unmarshal(data []byte, v any) error { - return customConfig.Unmarshal(data, v) -} - -func (j customJsonApi) MarshalIndent(v any, prefix, indent string) ([]byte, error) { - return customConfig.MarshalIndent(v, prefix, indent) -} - -func (j customJsonApi) NewEncoder(writer io.Writer) json.Encoder { - return customConfig.NewEncoder(writer) -} - -func (j customJsonApi) NewDecoder(reader io.Reader) json.Decoder { - return customConfig.NewDecoder(reader) -} - -func main() { - //Replace the default json api - json.API = customJsonApi{} - - //Start your gin engine - router := gin.Default() - router.Run(":8080") -} -``` - -## Don't trust all proxies +### Don't trust all proxies Gin lets you specify which headers to hold the real client IP (if any), as well as specifying which proxies (or direct clients) you trust to From 48667a2dd1172f94c43811c2545209abc59c43f4 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 13 Mar 2026 22:40:18 +0800 Subject: [PATCH 32/70] chore(deps): upgrade Go dependencies and CI action versions (#4580) - Bump golangci-lint from v2.9 to v2.11 - Bump aquasecurity/trivy-action from 0.34.2 to 0.35.0 - Upgrade golang.org/x packages (net, crypto, sys, text, arch) - Upgrade go-json, mimetype, and protobuf to latest patch versions Co-authored-by: Claude Opus 4.6 --- .github/workflows/gin.yml | 2 +- .github/workflows/trivy-scan.yml | 4 ++-- go.mod | 16 ++++++++-------- go.sum | 32 ++++++++++++++++---------------- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/.github/workflows/gin.yml b/.github/workflows/gin.yml index d909d22d..e8b4aea2 100644 --- a/.github/workflows/gin.yml +++ b/.github/workflows/gin.yml @@ -26,7 +26,7 @@ jobs: - name: Setup golangci-lint uses: golangci/golangci-lint-action@v9 with: - version: v2.9 + version: v2.11 args: --verbose test: needs: lint diff --git a/.github/workflows/trivy-scan.yml b/.github/workflows/trivy-scan.yml index 73a892bd..e3a26e5f 100644 --- a/.github/workflows/trivy-scan.yml +++ b/.github/workflows/trivy-scan.yml @@ -27,7 +27,7 @@ jobs: fetch-depth: 0 - name: Run Trivy vulnerability scanner (source code) - uses: aquasecurity/trivy-action@0.34.2 + uses: aquasecurity/trivy-action@0.35.0 with: scan-type: "fs" scan-ref: "." @@ -44,7 +44,7 @@ jobs: sarif_file: "trivy-results.sarif" - name: Run Trivy scanner (table output for logs) - uses: aquasecurity/trivy-action@0.34.2 + uses: aquasecurity/trivy-action@0.35.0 if: always() with: scan-type: "fs" diff --git a/go.mod b/go.mod index 4fe2ce4f..c5481db5 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/bytedance/sonic v1.15.0 github.com/gin-contrib/sse v1.1.0 github.com/go-playground/validator/v10 v10.30.1 - github.com/goccy/go-json v0.10.5 + github.com/goccy/go-json v0.10.6 github.com/goccy/go-yaml v1.19.2 github.com/json-iterator/go v1.1.12 github.com/mattn/go-isatty v0.0.20 @@ -16,8 +16,8 @@ require ( github.com/stretchr/testify v1.11.1 github.com/ugorji/go/codec v1.3.1 go.mongodb.org/mongo-driver/v2 v2.5.0 - golang.org/x/net v0.51.0 - google.golang.org/protobuf v1.36.10 + golang.org/x/net v0.52.0 + google.golang.org/protobuf v1.36.11 ) require gopkg.in/yaml.v3 v3.0.1 // indirect @@ -27,7 +27,7 @@ require ( github.com/bytedance/sonic/loader v0.5.0 // indirect github.com/cloudwego/base64x v0.1.6 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/gabriel-vasile/mimetype v1.4.12 // indirect + github.com/gabriel-vasile/mimetype v1.4.13 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/klauspost/cpuid/v2 v2.3.0 // indirect @@ -38,8 +38,8 @@ require ( github.com/quic-go/qpack v0.6.0 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect go.uber.org/mock v0.6.0 // indirect - golang.org/x/arch v0.22.0 // indirect - golang.org/x/crypto v0.48.0 // indirect - golang.org/x/sys v0.41.0 // indirect - golang.org/x/text v0.34.0 // indirect + golang.org/x/arch v0.25.0 // indirect + golang.org/x/crypto v0.49.0 // indirect + golang.org/x/sys v0.42.0 // indirect + golang.org/x/text v0.35.0 // indirect ) diff --git a/go.sum b/go.sum index a75260ce..a3b5b8a3 100644 --- a/go.sum +++ b/go.sum @@ -10,8 +10,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/gabriel-vasile/mimetype v1.4.12 h1:e9hWvmLYvtp846tLHam2o++qitpguFiYCKbn0w9jyqw= -github.com/gabriel-vasile/mimetype v1.4.12/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s= +github.com/gabriel-vasile/mimetype v1.4.13 h1:46nXokslUBsAJE/wMsp5gtO500a4F3Nkz9Ufpk2AcUM= +github.com/gabriel-vasile/mimetype v1.4.13/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s= github.com/gin-contrib/sse v1.1.0 h1:n0w2GMuUpWDVp7qSpvze6fAu9iRxJY4Hmj6AmBOU05w= github.com/gin-contrib/sse v1.1.0/go.mod h1:hxRZ5gVpWMT7Z0B0gSNYqqsSCNIJMjzvm6fqCz9vjwM= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= @@ -22,8 +22,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= github.com/go-playground/validator/v10 v10.30.1 h1:f3zDSN/zOma+w6+1Wswgd9fLkdwy06ntQJp0BBvFG0w= github.com/go-playground/validator/v10 v10.30.1/go.mod h1:oSuBIQzuJxL//3MelwSLD5hc2Tu889bF0Idm9Dg26cM= -github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4= -github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= +github.com/goccy/go-json v0.10.6 h1:p8HrPJzOakx/mn/bQtjgNjdTcN+/S6FcG2CTtQOrHVU= +github.com/goccy/go-json v0.10.6/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= github.com/goccy/go-yaml v1.19.2 h1:PmFC1S6h8ljIz6gMRBopkjP1TVT7xuwrButHID66PoM= github.com/goccy/go-yaml v1.19.2/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= @@ -75,19 +75,19 @@ go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0= go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y= go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU= -golang.org/x/arch v0.22.0 h1:c/Zle32i5ttqRXjdLyyHZESLD/bB90DCU1g9l/0YBDI= -golang.org/x/arch v0.22.0/go.mod h1:dNHoOeKiyja7GTvF9NJS1l3Z2yntpQNzgrjh1cU103A= -golang.org/x/crypto v0.48.0 h1:/VRzVqiRSggnhY7gNRxPauEQ5Drw9haKdM0jqfcCFts= -golang.org/x/crypto v0.48.0/go.mod h1:r0kV5h3qnFPlQnBSrULhlsRfryS2pmewsg+XfMgkVos= -golang.org/x/net v0.51.0 h1:94R/GTO7mt3/4wIKpcR5gkGmRLOuE/2hNGeWq/GBIFo= -golang.org/x/net v0.51.0/go.mod h1:aamm+2QF5ogm02fjy5Bb7CQ0WMt1/WVM7FtyaTLlA9Y= +golang.org/x/arch v0.25.0 h1:qnk6Ksugpi5Bz32947rkUgDt9/s5qvqDPl/gBKdMJLE= +golang.org/x/arch v0.25.0/go.mod h1:0X+GdSIP+kL5wPmpK7sdkEVTt2XoYP0cSjQSbZBwOi8= +golang.org/x/crypto v0.49.0 h1:+Ng2ULVvLHnJ/ZFEq4KdcDd/cfjrrjjNSXNzxg0Y4U4= +golang.org/x/crypto v0.49.0/go.mod h1:ErX4dUh2UM+CFYiXZRTcMpEcN8b/1gxEuv3nODoYtCA= +golang.org/x/net v0.52.0 h1:He/TN1l0e4mmR3QqHMT2Xab3Aj3L9qjbhRm78/6jrW0= +golang.org/x/net v0.52.0/go.mod h1:R1MAz7uMZxVMualyPXb+VaqGSa3LIaUqk0eEt3w36Sw= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k= -golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= -golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk= -golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA= -google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE= -google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= +golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo= +golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= +golang.org/x/text v0.35.0 h1:JOVx6vVDFokkpaq1AEptVzLTpDe9KGpj5tR4/X+ybL8= +golang.org/x/text v0.35.0/go.mod h1:khi/HExzZJ2pGnjenulevKNX1W67CUy0AsXcNubPGCA= +google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= +google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= From 6d880724cc553ccc902a88f7f871fd7ea0b44790 Mon Sep 17 00:00:00 2001 From: tsinglua Date: Fri, 13 Mar 2026 22:42:00 +0800 Subject: [PATCH 33/70] refactor(test): use the built-in max/min to simplify the code (#4576) Signed-off-by: tsinglua Co-authored-by: Bo-Yi Wu --- test_helpers.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test_helpers.go b/test_helpers.go index 20d20032..146be8f3 100644 --- a/test_helpers.go +++ b/test_helpers.go @@ -49,10 +49,7 @@ func waitForServerReady(url string, maxAttempts int) error { } // Exponential backoff: 10ms, 20ms, 40ms, 80ms, 160ms... - backoff := time.Duration(10*(1< 500*time.Millisecond { - backoff = 500 * time.Millisecond - } + backoff := min(time.Duration(10*(1< Date: Sun, 15 Mar 2026 14:17:04 +0800 Subject: [PATCH 34/70] docs(benchmarks): update benchmark report with Gin v1.12.0 results (#4581) - Update test environment to Apple M4 Pro, Go 1.25.8, macOS - Add table of contents for easier navigation - Add ranked summary tables for each API benchmark - Reorganize full results by API section with clear headings - Refresh all memory consumption and benchmark data Co-authored-by: Claude Opus 4.6 (1M context) --- BENCHMARKS.md | 1438 +++++++++++++++++++++++++++---------------------- 1 file changed, 803 insertions(+), 635 deletions(-) diff --git a/BENCHMARKS.md b/BENCHMARKS.md index c11ee99a..fc24af68 100644 --- a/BENCHMARKS.md +++ b/BENCHMARKS.md @@ -1,666 +1,834 @@ +# Gin Benchmark Report -# Benchmark System - -**VM HOST:** Travis -**Machine:** Ubuntu 16.04.6 LTS x64 -**Date:** May 04th, 2020 -**Version:** Gin v1.6.3 -**Go Version:** 1.14.2 linux/amd64 +**Machine:** Apple M4 Pro +**OS:** macOS (Darwin 25.3.0), arm64 +**Date:** March 15th, 2026 +**Gin Version:** v1.12.0 +**Go Version:** 1.25.8 darwin/arm64 **Source:** [Go HTTP Router Benchmark](https://github.com/gin-gonic/go-http-routing-benchmark) -**Result:** [See the gist](https://gist.github.com/appleboy/b5f2ecfaf50824ae9c64dcfb9165ae5e) or [Travis result](https://travis-ci.org/github/gin-gonic/go-http-routing-benchmark/jobs/682947061) -## Static Routes: 157 +--- -```sh -Gin: 34936 Bytes +## Table of Contents -HttpServeMux: 14512 Bytes -Ace: 30680 Bytes -Aero: 34536 Bytes -Bear: 30456 Bytes -Beego: 98456 Bytes -Bone: 40224 Bytes -Chi: 83608 Bytes -Denco: 10216 Bytes -Echo: 80328 Bytes -GocraftWeb: 55288 Bytes -Goji: 29744 Bytes -Gojiv2: 105840 Bytes -GoJsonRest: 137496 Bytes -GoRestful: 816936 Bytes -GorillaMux: 585632 Bytes -GowwwRouter: 24968 Bytes -HttpRouter: 21712 Bytes -HttpTreeMux: 73448 Bytes -Kocha: 115472 Bytes -LARS: 30640 Bytes -Macaron: 38592 Bytes -Martini: 310864 Bytes -Pat: 19696 Bytes -Possum: 89920 Bytes -R2router: 23712 Bytes -Rivet: 24608 Bytes -Tango: 28264 Bytes -TigerTonic: 78768 Bytes -Traffic: 538976 Bytes -Vulcan: 369960 Bytes -``` +- [Memory Consumption](#memory-consumption) +- [Benchmark Summary](#benchmark-summary) + - [GitHub API (203 routes)](#github-api-all-routes) + - [Google+ API (13 routes)](#google-api-all-routes) + - [Parse API (26 routes)](#parse-api-all-routes) + - [Static Routes (157 routes)](#static-routes-all) +- [Micro Benchmarks](#micro-benchmarks) +- [Full Benchmark Results](#full-benchmark-results) -## GithubAPI Routes: 203 +--- -```sh -Gin: 58512 Bytes +## Memory Consumption -Ace: 48688 Bytes -Aero: 318568 Bytes -Bear: 84248 Bytes -Beego: 150936 Bytes -Bone: 100976 Bytes -Chi: 95112 Bytes -Denco: 36736 Bytes -Echo: 100296 Bytes -GocraftWeb: 95432 Bytes -Goji: 49680 Bytes -Gojiv2: 104704 Bytes -GoJsonRest: 141976 Bytes -GoRestful: 1241656 Bytes -GorillaMux: 1322784 Bytes -GowwwRouter: 80008 Bytes -HttpRouter: 37144 Bytes -HttpTreeMux: 78800 Bytes -Kocha: 785120 Bytes -LARS: 48600 Bytes -Macaron: 92784 Bytes -Martini: 485264 Bytes -Pat: 21200 Bytes -Possum: 85312 Bytes -R2router: 47104 Bytes -Rivet: 42840 Bytes -Tango: 54840 Bytes -TigerTonic: 95264 Bytes -Traffic: 921744 Bytes -Vulcan: 425992 Bytes -``` +Memory required for loading the routing structure (lower is better). -## GPlusAPI Routes: 13 +### Static Routes: 157 -```sh -Gin: 4384 Bytes +| Router | Bytes | +|:-------|------:| +| **Denco** | **9,928** | +| **Pat** | **20,200** | +| **HttpRouter** | **21,680** | +| GowwwRouter | 24,512 | +| R2router | 23,256 | +| Rivet | 24,608 | +| Aero | 28,728 | +| Tango | 28,296 | +| Bear | 29,984 | +| Goji | 27,216 | +| Ace | 30,648 | +| LARS | 30,640 | +| Gin | 34,408 | +| Macaron | 36,976 | +| Bone | 40,480 | +| GocraftWeb | 55,088 | +| HttpServeMux | 71,728 | +| HttpTreeMux | 73,448 | +| TigerTonic | 78,328 | +| Chi | 83,160 | +| Possum | 88,672 | +| Echo | 91,976 | +| Beego | 98,824 | +| Gojiv2 | 117,952 | +| Kocha | 123,160 | +| GoJsonRest | 136,296 | +| Martini | 314,360 | +| Vulcan | 367,064 | +| Traffic | 555,248 | +| GorillaMux | 599,496 | +| GoRestful | 819,704 | -Ace: 3712 Bytes -Aero: 26056 Bytes -Bear: 7112 Bytes -Beego: 10272 Bytes -Bone: 6688 Bytes -Chi: 8024 Bytes -Denco: 3264 Bytes -Echo: 9688 Bytes -GocraftWeb: 7496 Bytes -Goji: 3152 Bytes -Gojiv2: 7376 Bytes -GoJsonRest: 11400 Bytes -GoRestful: 74328 Bytes -GorillaMux: 66208 Bytes -GowwwRouter: 5744 Bytes -HttpRouter: 2808 Bytes -HttpTreeMux: 7440 Bytes -Kocha: 128880 Bytes -LARS: 3656 Bytes -Macaron: 8656 Bytes -Martini: 23920 Bytes -Pat: 1856 Bytes -Possum: 7248 Bytes -R2router: 3928 Bytes -Rivet: 3064 Bytes -Tango: 5168 Bytes -TigerTonic: 9408 Bytes -Traffic: 46400 Bytes -Vulcan: 25544 Bytes -``` +### GitHub API Routes: 203 -## ParseAPI Routes: 26 +| Router | Bytes | +|:-------|------:| +| **Pat** | **19,400** | +| **Denco** | **35,360** | +| **HttpRouter** | **37,072** | +| Rivet | 42,840 | +| Goji | 46,416 | +| R2router | 46,616 | +| Ace | 48,616 | +| LARS | 48,592 | +| Tango | 54,872 | +| Gin | 58,840 | +| Bear | 80,528 | +| Possum | 81,832 | +| GowwwRouter | 86,656 | +| HttpTreeMux | 78,800 | +| Macaron | 90,632 | +| GocraftWeb | 93,896 | +| Chi | 94,888 | +| TigerTonic | 95,104 | +| Bone | 100,080 | +| Echo | 117,784 | +| Gojiv2 | 118,640 | +| GoJsonRest | 141,120 | +| Beego | 150,840 | +| Martini | 474,792 | +| Aero | 524,992 | +| Kocha | 784,144 | +| Traffic | 916,720 | +| GoRestful | 1,270,720 | +| GorillaMux | 1,319,696 | +| Vulcan | 423,216 | -```sh -Gin: 7776 Bytes +### Google+ API Routes: 13 -Ace: 6704 Bytes -Aero: 28488 Bytes -Bear: 12320 Bytes -Beego: 19280 Bytes -Bone: 11440 Bytes -Chi: 9744 Bytes -Denco: 4192 Bytes -Echo: 11664 Bytes -GocraftWeb: 12800 Bytes -Goji: 5680 Bytes -Gojiv2: 14464 Bytes -GoJsonRest: 14072 Bytes -GoRestful: 116264 Bytes -GorillaMux: 105880 Bytes -GowwwRouter: 9344 Bytes -HttpRouter: 5072 Bytes -HttpTreeMux: 7848 Bytes -Kocha: 181712 Bytes -LARS: 6632 Bytes -Macaron: 13648 Bytes -Martini: 45888 Bytes -Pat: 2560 Bytes -Possum: 9200 Bytes -R2router: 7056 Bytes -Rivet: 5680 Bytes -Tango: 8920 Bytes -TigerTonic: 9840 Bytes -Traffic: 79096 Bytes -Vulcan: 44504 Bytes -``` +| Router | Bytes | +|:-------|------:| +| **Pat** | **1,848** | +| **HttpRouter** | **2,776** | +| **Goji** | **2,928** | +| Rivet | 3,064 | +| Denco | 3,224 | +| Ace | 3,680 | +| LARS | 3,656 | +| R2router | 3,864 | +| Gin | 4,576 | +| Tango | 5,200 | +| GowwwRouter | 6,168 | +| Bone | 6,688 | +| Bear | 7,096 | +| GocraftWeb | 7,480 | +| HttpTreeMux | 7,440 | +| Gojiv2 | 8,096 | +| Chi | 8,008 | +| Macaron | 8,672 | +| TigerTonic | 9,392 | +| Echo | 10,968 | +| Beego | 10,256 | +| GoJsonRest | 11,432 | +| Martini | 24,656 | +| Aero | 25,744 | +| Vulcan | 25,448 | +| Traffic | 48,176 | +| GorillaMux | 68,000 | +| GoRestful | 72,536 | +| Kocha | 128,880 | +| Possum | 7,192 | -## Static Routes +### Parse API Routes: 26 -```sh -BenchmarkGin_StaticAll 62169 19319 ns/op 0 B/op 0 allocs/op +| Router | Bytes | +|:-------|------:| +| **Pat** | **2,552** | +| **Denco** | **4,080** | +| **HttpRouter** | **5,024** | +| Goji | 5,248 | +| Rivet | 5,680 | +| Ace | 6,656 | +| LARS | 6,632 | +| R2router | 6,920 | +| Gin | 7,896 | +| HttpTreeMux | 7,848 | +| Possum | 8,104 | +| Bear | 12,256 | +| Tango | 8,952 | +| Chi | 9,656 | +| GowwwRouter | 10,048 | +| TigerTonic | 9,808 | +| Bone | 11,440 | +| GocraftWeb | 12,752 | +| Echo | 13,816 | +| Macaron | 13,704 | +| GoJsonRest | 14,112 | +| Gojiv2 | 16,064 | +| Beego | 19,256 | +| Aero | 28,152 | +| Martini | 43,760 | +| Traffic | 78,832 | +| Vulcan | 44,024 | +| GorillaMux | 105,384 | +| GoRestful | 121,200 | +| Kocha | 181,712 | -BenchmarkAce_StaticAll 65428 18313 ns/op 0 B/op 0 allocs/op -BenchmarkAero_StaticAll 121132 9632 ns/op 0 B/op 0 allocs/op -BenchmarkHttpServeMux_StaticAll 52626 22758 ns/op 0 B/op 0 allocs/op -BenchmarkBeego_StaticAll 9962 179058 ns/op 55264 B/op 471 allocs/op -BenchmarkBear_StaticAll 14894 80966 ns/op 20272 B/op 469 allocs/op -BenchmarkBone_StaticAll 18718 64065 ns/op 0 B/op 0 allocs/op -BenchmarkChi_StaticAll 10000 149827 ns/op 67824 B/op 471 allocs/op -BenchmarkDenco_StaticAll 211393 5680 ns/op 0 B/op 0 allocs/op -BenchmarkEcho_StaticAll 49341 24343 ns/op 0 B/op 0 allocs/op -BenchmarkGocraftWeb_StaticAll 10000 126209 ns/op 46312 B/op 785 allocs/op -BenchmarkGoji_StaticAll 27956 43174 ns/op 0 B/op 0 allocs/op -BenchmarkGojiv2_StaticAll 3430 370718 ns/op 205984 B/op 1570 allocs/op -BenchmarkGoJsonRest_StaticAll 9134 188888 ns/op 51653 B/op 1727 allocs/op -BenchmarkGoRestful_StaticAll 706 1703330 ns/op 613280 B/op 2053 allocs/op -BenchmarkGorillaMux_StaticAll 1268 924083 ns/op 153233 B/op 1413 allocs/op -BenchmarkGowwwRouter_StaticAll 63374 18935 ns/op 0 B/op 0 allocs/op -BenchmarkHttpRouter_StaticAll 109938 10902 ns/op 0 B/op 0 allocs/op -BenchmarkHttpTreeMux_StaticAll 109166 10861 ns/op 0 B/op 0 allocs/op -BenchmarkKocha_StaticAll 92258 12992 ns/op 0 B/op 0 allocs/op -BenchmarkLARS_StaticAll 65200 18387 ns/op 0 B/op 0 allocs/op -BenchmarkMacaron_StaticAll 5671 291501 ns/op 115553 B/op 1256 allocs/op -BenchmarkMartini_StaticAll 807 1460498 ns/op 125444 B/op 1717 allocs/op -BenchmarkPat_StaticAll 513 2342396 ns/op 602832 B/op 12559 allocs/op -BenchmarkPossum_StaticAll 10000 128270 ns/op 65312 B/op 471 allocs/op -BenchmarkR2router_StaticAll 16726 71760 ns/op 22608 B/op 628 allocs/op -BenchmarkRivet_StaticAll 41722 28723 ns/op 0 B/op 0 allocs/op -BenchmarkTango_StaticAll 7606 205082 ns/op 39209 B/op 1256 allocs/op -BenchmarkTigerTonic_StaticAll 26247 45806 ns/op 7376 B/op 157 allocs/op -BenchmarkTraffic_StaticAll 550 2284518 ns/op 754864 B/op 14601 allocs/op -BenchmarkVulcan_StaticAll 10000 131343 ns/op 15386 B/op 471 allocs/op -``` +--- + +## Benchmark Summary + +The tables below highlight the **top performers** across each major API benchmark. +Gin consistently ranks among the fastest routers with **zero memory allocations**. + +### GitHub API (All Routes) + +Routing all 203 GitHub API endpoints per operation. + +| Rank | Router | Time (ns/op) | Bytes (B/op) | Allocs/op | +|:----:|:-------|-------------:|-------------:|----------:| +| 1 | **Aero** | 6,646 | 0 | 0 | +| 2 | **LARS** | 8,714 | 0 | 0 | +| 3 | **Gin** | 9,058 | 0 | 0 | +| 4 | Echo | 12,030 | 0 | 0 | +| 5 | HttpRouter | 13,840 | 13,792 | 167 | +| 6 | Ace | 21,354 | 13,792 | 167 | +| 7 | Denco | 22,401 | 20,224 | 167 | +| 8 | Rivet | 23,337 | 16,272 | 167 | +| 9 | Kocha | 33,213 | 20,592 | 504 | +| 10 | GowwwRouter | 35,511 | 61,456 | 334 | +| ... | ... | ... | ... | ... | +| 28 | GorillaMux | 1,282,012 | 225,666 | 1,588 | +| 29 | Pat | 1,432,291 | 1,421,792 | 23,019 | +| 30 | Martini | 1,483,537 | 231,418 | 2,731 | + +### Google+ API (All Routes) + +Routing all 13 Google+ API endpoints per operation. + +| Rank | Router | Time (ns/op) | Bytes (B/op) | Allocs/op | +|:----:|:-------|-------------:|-------------:|----------:| +| 1 | **Aero** | 323.2 | 0 | 0 | +| 2 | **LARS** | 382.6 | 0 | 0 | +| 3 | **Gin** | 412.3 | 0 | 0 | +| 4 | Echo | 426.0 | 0 | 0 | +| 5 | HttpRouter | 649.1 | 640 | 11 | +| 6 | Denco | 910.9 | 672 | 11 | +| 7 | Ace | 912.1 | 640 | 11 | +| 8 | Rivet | 928.1 | 768 | 11 | +| 9 | Kocha | 1,323 | 848 | 27 | +| 10 | GowwwRouter | 1,858 | 4,048 | 22 | +| ... | ... | ... | ... | ... | +| 28 | Traffic | 22,350 | 26,616 | 366 | +| 29 | GoRestful | 23,142 | 60,720 | 193 | +| 30 | Martini | 24,600 | 14,328 | 171 | + +### Parse API (All Routes) + +Routing all 26 Parse API endpoints per operation. + +| Rank | Router | Time (ns/op) | Bytes (B/op) | Allocs/op | +|:----:|:-------|-------------:|-------------:|----------:| +| 1 | **Aero** | 546.0 | 0 | 0 | +| 2 | **LARS** | 669.4 | 0 | 0 | +| 3 | **Gin** | 719.8 | 0 | 0 | +| 4 | Echo | 723.0 | 0 | 0 | +| 5 | HttpRouter | 921.5 | 640 | 16 | +| 6 | Denco | 1,291 | 928 | 16 | +| 7 | Rivet | 1,385 | 912 | 16 | +| 8 | Ace | 1,445 | 640 | 16 | +| 9 | Kocha | 1,813 | 960 | 35 | +| 10 | GowwwRouter | 2,924 | 5,888 | 32 | +| ... | ... | ... | ... | ... | +| 28 | Traffic | 34,164 | 45,760 | 630 | +| 29 | Martini | 39,785 | 25,696 | 305 | +| 30 | GoRestful | 52,633 | 131,728 | 380 | + +### Static Routes (All) + +Routing all 157 static routes per operation. + +| Rank | Router | Time (ns/op) | Bytes (B/op) | Allocs/op | +|:----:|:-------|-------------:|-------------:|----------:| +| 1 | **Denco** | 2,240 | 0 | 0 | +| 2 | **Aero** | 2,872 | 0 | 0 | +| 3 | **HttpTreeMux** | 4,031 | 0 | 0 | +| 4 | HttpRouter | 4,095 | 0 | 0 | +| 5 | LARS | 5,272 | 0 | 0 | +| 6 | Gin | 5,566 | 0 | 0 | +| 7 | Ace | 5,981 | 0 | 0 | +| 8 | Kocha | 6,013 | 0 | 0 | +| 9 | GowwwRouter | 6,622 | 0 | 0 | +| 10 | Echo | 6,714 | 0 | 0 | +| ... | ... | ... | ... | ... | +| 28 | Martini | 577,268 | 129,209 | 2,031 | +| 29 | Traffic | 699,470 | 749,837 | 14,444 | +| 30 | Pat | 813,157 | 602,832 | 12,559 | + +--- ## Micro Benchmarks -```sh -BenchmarkGin_Param 18785022 63.9 ns/op 0 B/op 0 allocs/op +### Single Parameter -BenchmarkAce_Param 14689765 81.5 ns/op 0 B/op 0 allocs/op -BenchmarkAero_Param 23094770 51.2 ns/op 0 B/op 0 allocs/op -BenchmarkBear_Param 1417045 845 ns/op 456 B/op 5 allocs/op -BenchmarkBeego_Param 1000000 1080 ns/op 352 B/op 3 allocs/op -BenchmarkBone_Param 1000000 1463 ns/op 816 B/op 6 allocs/op -BenchmarkChi_Param 1378756 885 ns/op 432 B/op 3 allocs/op -BenchmarkDenco_Param 8557899 143 ns/op 32 B/op 1 allocs/op -BenchmarkEcho_Param 16433347 75.5 ns/op 0 B/op 0 allocs/op -BenchmarkGocraftWeb_Param 1000000 1218 ns/op 648 B/op 8 allocs/op -BenchmarkGoji_Param 1921248 617 ns/op 336 B/op 2 allocs/op -BenchmarkGojiv2_Param 561848 2156 ns/op 1328 B/op 11 allocs/op -BenchmarkGoJsonRest_Param 1000000 1358 ns/op 649 B/op 13 allocs/op -BenchmarkGoRestful_Param 224857 5307 ns/op 4192 B/op 14 allocs/op -BenchmarkGorillaMux_Param 498313 2459 ns/op 1280 B/op 10 allocs/op -BenchmarkGowwwRouter_Param 1864354 654 ns/op 432 B/op 3 allocs/op -BenchmarkHttpRouter_Param 26269074 47.7 ns/op 0 B/op 0 allocs/op -BenchmarkHttpTreeMux_Param 2109829 557 ns/op 352 B/op 3 allocs/op -BenchmarkKocha_Param 5050216 243 ns/op 56 B/op 3 allocs/op -BenchmarkLARS_Param 19811712 59.9 ns/op 0 B/op 0 allocs/op -BenchmarkMacaron_Param 662746 2329 ns/op 1072 B/op 10 allocs/op -BenchmarkMartini_Param 279902 4260 ns/op 1072 B/op 10 allocs/op -BenchmarkPat_Param 1000000 1382 ns/op 536 B/op 11 allocs/op -BenchmarkPossum_Param 1000000 1014 ns/op 496 B/op 5 allocs/op -BenchmarkR2router_Param 1712559 707 ns/op 432 B/op 5 allocs/op -BenchmarkRivet_Param 6648086 182 ns/op 48 B/op 1 allocs/op -BenchmarkTango_Param 1221504 994 ns/op 248 B/op 8 allocs/op -BenchmarkTigerTonic_Param 891661 2261 ns/op 776 B/op 16 allocs/op -BenchmarkTraffic_Param 350059 3598 ns/op 1856 B/op 21 allocs/op -BenchmarkVulcan_Param 2517823 472 ns/op 98 B/op 3 allocs/op -BenchmarkAce_Param5 9214365 130 ns/op 0 B/op 0 allocs/op -BenchmarkAero_Param5 15369013 77.9 ns/op 0 B/op 0 allocs/op -BenchmarkBear_Param5 1000000 1113 ns/op 501 B/op 5 allocs/op -BenchmarkBeego_Param5 1000000 1269 ns/op 352 B/op 3 allocs/op -BenchmarkBone_Param5 986820 1873 ns/op 864 B/op 6 allocs/op -BenchmarkChi_Param5 1000000 1156 ns/op 432 B/op 3 allocs/op -BenchmarkDenco_Param5 3036331 400 ns/op 160 B/op 1 allocs/op -BenchmarkEcho_Param5 6447133 186 ns/op 0 B/op 0 allocs/op -BenchmarkGin_Param5 10786068 110 ns/op 0 B/op 0 allocs/op -BenchmarkGocraftWeb_Param5 844820 1944 ns/op 920 B/op 11 allocs/op -BenchmarkGoji_Param5 1474965 827 ns/op 336 B/op 2 allocs/op -BenchmarkGojiv2_Param5 442820 2516 ns/op 1392 B/op 11 allocs/op -BenchmarkGoJsonRest_Param5 507555 2711 ns/op 1097 B/op 16 allocs/op -BenchmarkGoRestful_Param5 216481 6093 ns/op 4288 B/op 14 allocs/op -BenchmarkGorillaMux_Param5 314402 3628 ns/op 1344 B/op 10 allocs/op -BenchmarkGowwwRouter_Param5 1624660 733 ns/op 432 B/op 3 allocs/op -BenchmarkHttpRouter_Param5 13167324 92.0 ns/op 0 B/op 0 allocs/op -BenchmarkHttpTreeMux_Param5 1000000 1295 ns/op 576 B/op 6 allocs/op -BenchmarkKocha_Param5 1000000 1138 ns/op 440 B/op 10 allocs/op -BenchmarkLARS_Param5 11580613 105 ns/op 0 B/op 0 allocs/op -BenchmarkMacaron_Param5 473596 2755 ns/op 1072 B/op 10 allocs/op -BenchmarkMartini_Param5 230756 5111 ns/op 1232 B/op 11 allocs/op -BenchmarkPat_Param5 469190 3370 ns/op 888 B/op 29 allocs/op -BenchmarkPossum_Param5 1000000 1002 ns/op 496 B/op 5 allocs/op -BenchmarkR2router_Param5 1422129 844 ns/op 432 B/op 5 allocs/op -BenchmarkRivet_Param5 2263789 539 ns/op 240 B/op 1 allocs/op -BenchmarkTango_Param5 1000000 1256 ns/op 360 B/op 8 allocs/op -BenchmarkTigerTonic_Param5 175500 7492 ns/op 2279 B/op 39 allocs/op -BenchmarkTraffic_Param5 233631 5816 ns/op 2208 B/op 27 allocs/op -BenchmarkVulcan_Param5 1923416 629 ns/op 98 B/op 3 allocs/op -BenchmarkAce_Param20 4321266 281 ns/op 0 B/op 0 allocs/op -BenchmarkAero_Param20 31501641 35.2 ns/op 0 B/op 0 allocs/op -BenchmarkBear_Param20 335204 3489 ns/op 1665 B/op 5 allocs/op -BenchmarkBeego_Param20 503674 2860 ns/op 352 B/op 3 allocs/op -BenchmarkBone_Param20 298922 4741 ns/op 2031 B/op 6 allocs/op -BenchmarkChi_Param20 878181 1957 ns/op 432 B/op 3 allocs/op -BenchmarkDenco_Param20 1000000 1360 ns/op 640 B/op 1 allocs/op -BenchmarkEcho_Param20 2104946 580 ns/op 0 B/op 0 allocs/op -BenchmarkGin_Param20 4167204 290 ns/op 0 B/op 0 allocs/op -BenchmarkGocraftWeb_Param20 173064 7514 ns/op 3796 B/op 15 allocs/op -BenchmarkGoji_Param20 458778 2651 ns/op 1247 B/op 2 allocs/op -BenchmarkGojiv2_Param20 364862 3178 ns/op 1632 B/op 11 allocs/op -BenchmarkGoJsonRest_Param20 125514 9760 ns/op 4485 B/op 20 allocs/op -BenchmarkGoRestful_Param20 101217 11964 ns/op 6715 B/op 18 allocs/op -BenchmarkGorillaMux_Param20 147654 8132 ns/op 3452 B/op 12 allocs/op -BenchmarkGowwwRouter_Param20 1000000 1225 ns/op 432 B/op 3 allocs/op -BenchmarkHttpRouter_Param20 4920895 247 ns/op 0 B/op 0 allocs/op -BenchmarkHttpTreeMux_Param20 173202 6605 ns/op 3196 B/op 10 allocs/op -BenchmarkKocha_Param20 345988 3620 ns/op 1808 B/op 27 allocs/op -BenchmarkLARS_Param20 4592326 262 ns/op 0 B/op 0 allocs/op -BenchmarkMacaron_Param20 166492 7286 ns/op 2924 B/op 12 allocs/op -BenchmarkMartini_Param20 122162 10653 ns/op 3595 B/op 13 allocs/op -BenchmarkPat_Param20 78630 15239 ns/op 4424 B/op 93 allocs/op -BenchmarkPossum_Param20 1000000 1008 ns/op 496 B/op 5 allocs/op -BenchmarkR2router_Param20 294981 4587 ns/op 2284 B/op 7 allocs/op -BenchmarkRivet_Param20 691798 2090 ns/op 1024 B/op 1 allocs/op -BenchmarkTango_Param20 842440 2505 ns/op 856 B/op 8 allocs/op -BenchmarkTigerTonic_Param20 38614 31509 ns/op 9870 B/op 119 allocs/op -BenchmarkTraffic_Param20 57633 21107 ns/op 7853 B/op 47 allocs/op -BenchmarkVulcan_Param20 1000000 1178 ns/op 98 B/op 3 allocs/op -BenchmarkAce_ParamWrite 7330743 180 ns/op 8 B/op 1 allocs/op -BenchmarkAero_ParamWrite 13833598 86.7 ns/op 0 B/op 0 allocs/op -BenchmarkBear_ParamWrite 1363321 867 ns/op 456 B/op 5 allocs/op -BenchmarkBeego_ParamWrite 1000000 1104 ns/op 360 B/op 4 allocs/op -BenchmarkBone_ParamWrite 1000000 1475 ns/op 816 B/op 6 allocs/op -BenchmarkChi_ParamWrite 1320590 892 ns/op 432 B/op 3 allocs/op -BenchmarkDenco_ParamWrite 7093605 172 ns/op 32 B/op 1 allocs/op -BenchmarkEcho_ParamWrite 8434424 161 ns/op 8 B/op 1 allocs/op -BenchmarkGin_ParamWrite 10377034 118 ns/op 0 B/op 0 allocs/op -BenchmarkGocraftWeb_ParamWrite 1000000 1266 ns/op 656 B/op 9 allocs/op -BenchmarkGoji_ParamWrite 1874168 654 ns/op 336 B/op 2 allocs/op -BenchmarkGojiv2_ParamWrite 459032 2352 ns/op 1360 B/op 13 allocs/op -BenchmarkGoJsonRest_ParamWrite 499434 2145 ns/op 1128 B/op 18 allocs/op -BenchmarkGoRestful_ParamWrite 241087 5470 ns/op 4200 B/op 15 allocs/op -BenchmarkGorillaMux_ParamWrite 425686 2522 ns/op 1280 B/op 10 allocs/op -BenchmarkGowwwRouter_ParamWrite 922172 1778 ns/op 976 B/op 8 allocs/op -BenchmarkHttpRouter_ParamWrite 15392049 77.7 ns/op 0 B/op 0 allocs/op -BenchmarkHttpTreeMux_ParamWrite 1973385 597 ns/op 352 B/op 3 allocs/op -BenchmarkKocha_ParamWrite 4262500 281 ns/op 56 B/op 3 allocs/op -BenchmarkLARS_ParamWrite 10764410 113 ns/op 0 B/op 0 allocs/op -BenchmarkMacaron_ParamWrite 486769 2726 ns/op 1176 B/op 14 allocs/op -BenchmarkMartini_ParamWrite 264804 4842 ns/op 1176 B/op 14 allocs/op -BenchmarkPat_ParamWrite 735116 2047 ns/op 960 B/op 15 allocs/op -BenchmarkPossum_ParamWrite 1000000 1004 ns/op 496 B/op 5 allocs/op -BenchmarkR2router_ParamWrite 1592136 768 ns/op 432 B/op 5 allocs/op -BenchmarkRivet_ParamWrite 3582051 339 ns/op 112 B/op 2 allocs/op -BenchmarkTango_ParamWrite 2237337 534 ns/op 136 B/op 4 allocs/op -BenchmarkTigerTonic_ParamWrite 439608 3136 ns/op 1216 B/op 21 allocs/op -BenchmarkTraffic_ParamWrite 306979 4328 ns/op 2280 B/op 25 allocs/op -BenchmarkVulcan_ParamWrite 2529973 472 ns/op 98 B/op 3 allocs/op +``` +BenchmarkGin_Param 50441539 24.05 ns/op 0 B/op 0 allocs/op +BenchmarkAce_Param 24363132 50.00 ns/op 32 B/op 1 allocs/op +BenchmarkAero_Param 77342221 15.49 ns/op 0 B/op 0 allocs/op +BenchmarkBear_Param 4424601 271.1 ns/op 456 B/op 5 allocs/op +BenchmarkBeego_Param 3209640 381.4 ns/op 352 B/op 3 allocs/op +BenchmarkBone_Param 2987578 432.5 ns/op 752 B/op 5 allocs/op +BenchmarkChi_Param 3111004 358.4 ns/op 704 B/op 4 allocs/op +BenchmarkDenco_Param 28276489 40.28 ns/op 32 B/op 1 allocs/op +BenchmarkEcho_Param 65189638 18.99 ns/op 0 B/op 0 allocs/op +BenchmarkGocraftWeb_Param 3556015 340.4 ns/op 624 B/op 7 allocs/op +BenchmarkGoji_Param 6142947 198.9 ns/op 336 B/op 2 allocs/op +BenchmarkGojiv2_Param 2446671 540.1 ns/op 1136 B/op 8 allocs/op +BenchmarkGoJsonRest_Param 2730858 419.8 ns/op 617 B/op 13 allocs/op +BenchmarkGoRestful_Param 784556 1549 ns/op 4600 B/op 15 allocs/op +BenchmarkGorillaMux_Param 1857164 650.0 ns/op 1152 B/op 8 allocs/op +BenchmarkGowwwRouter_Param 8161994 147.8 ns/op 368 B/op 2 allocs/op +BenchmarkHttpRouter_Param 35229486 31.71 ns/op 32 B/op 1 allocs/op +BenchmarkHttpTreeMux_Param 6598603 186.5 ns/op 352 B/op 3 allocs/op +BenchmarkKocha_Param 18681621 61.98 ns/op 48 B/op 2 allocs/op +BenchmarkLARS_Param 60355720 20.04 ns/op 0 B/op 0 allocs/op +BenchmarkMacaron_Param 1669972 725.6 ns/op 1064 B/op 10 allocs/op +BenchmarkMartini_Param 993966 1343 ns/op 1096 B/op 12 allocs/op +BenchmarkPat_Param 2232280 481.9 ns/op 552 B/op 12 allocs/op +BenchmarkPossum_Param 3422949 349.7 ns/op 496 B/op 5 allocs/op +BenchmarkR2router_Param 6040192 198.3 ns/op 400 B/op 4 allocs/op +BenchmarkRivet_Param 25981898 46.35 ns/op 48 B/op 1 allocs/op +BenchmarkTango_Param 4682972 249.3 ns/op 192 B/op 6 allocs/op +BenchmarkTigerTonic_Param 1715374 688.0 ns/op 744 B/op 16 allocs/op +BenchmarkTraffic_Param 938739 1240 ns/op 1888 B/op 23 allocs/op +BenchmarkVulcan_Param 9498867 124.1 ns/op 98 B/op 3 allocs/op ``` -## GitHub +### 5 Parameters -```sh -BenchmarkGin_GithubStatic 15629472 76.7 ns/op 0 B/op 0 allocs/op - -BenchmarkAce_GithubStatic 15542612 75.9 ns/op 0 B/op 0 allocs/op -BenchmarkAero_GithubStatic 24777151 48.5 ns/op 0 B/op 0 allocs/op -BenchmarkBear_GithubStatic 2788894 435 ns/op 120 B/op 3 allocs/op -BenchmarkBeego_GithubStatic 1000000 1064 ns/op 352 B/op 3 allocs/op -BenchmarkBone_GithubStatic 93507 12838 ns/op 2880 B/op 60 allocs/op -BenchmarkChi_GithubStatic 1387743 860 ns/op 432 B/op 3 allocs/op -BenchmarkDenco_GithubStatic 39384996 30.4 ns/op 0 B/op 0 allocs/op -BenchmarkEcho_GithubStatic 12076382 99.1 ns/op 0 B/op 0 allocs/op -BenchmarkGocraftWeb_GithubStatic 1596495 756 ns/op 296 B/op 5 allocs/op -BenchmarkGoji_GithubStatic 6364876 189 ns/op 0 B/op 0 allocs/op -BenchmarkGojiv2_GithubStatic 550202 2098 ns/op 1312 B/op 10 allocs/op -BenchmarkGoRestful_GithubStatic 102183 12552 ns/op 4256 B/op 13 allocs/op -BenchmarkGoJsonRest_GithubStatic 1000000 1029 ns/op 329 B/op 11 allocs/op -BenchmarkGorillaMux_GithubStatic 255552 5190 ns/op 976 B/op 9 allocs/op -BenchmarkGowwwRouter_GithubStatic 15531916 77.1 ns/op 0 B/op 0 allocs/op -BenchmarkHttpRouter_GithubStatic 27920724 43.1 ns/op 0 B/op 0 allocs/op -BenchmarkHttpTreeMux_GithubStatic 21448953 55.8 ns/op 0 B/op 0 allocs/op -BenchmarkKocha_GithubStatic 21405310 56.0 ns/op 0 B/op 0 allocs/op -BenchmarkLARS_GithubStatic 13625156 89.0 ns/op 0 B/op 0 allocs/op -BenchmarkMacaron_GithubStatic 1000000 1747 ns/op 736 B/op 8 allocs/op -BenchmarkMartini_GithubStatic 187186 7326 ns/op 768 B/op 9 allocs/op -BenchmarkPat_GithubStatic 109143 11563 ns/op 3648 B/op 76 allocs/op -BenchmarkPossum_GithubStatic 1575898 770 ns/op 416 B/op 3 allocs/op -BenchmarkR2router_GithubStatic 3046231 404 ns/op 144 B/op 4 allocs/op -BenchmarkRivet_GithubStatic 11484826 105 ns/op 0 B/op 0 allocs/op -BenchmarkTango_GithubStatic 1000000 1153 ns/op 248 B/op 8 allocs/op -BenchmarkTigerTonic_GithubStatic 4929780 249 ns/op 48 B/op 1 allocs/op -BenchmarkTraffic_GithubStatic 106351 11819 ns/op 4664 B/op 90 allocs/op -BenchmarkVulcan_GithubStatic 1613271 722 ns/op 98 B/op 3 allocs/op -BenchmarkAce_GithubParam 8386032 143 ns/op 0 B/op 0 allocs/op -BenchmarkAero_GithubParam 11816200 102 ns/op 0 B/op 0 allocs/op -BenchmarkBear_GithubParam 1000000 1012 ns/op 496 B/op 5 allocs/op -BenchmarkBeego_GithubParam 1000000 1157 ns/op 352 B/op 3 allocs/op -BenchmarkBone_GithubParam 184653 6912 ns/op 1888 B/op 19 allocs/op -BenchmarkChi_GithubParam 1000000 1102 ns/op 432 B/op 3 allocs/op -BenchmarkDenco_GithubParam 3484798 352 ns/op 128 B/op 1 allocs/op -BenchmarkEcho_GithubParam 6337380 189 ns/op 0 B/op 0 allocs/op -BenchmarkGin_GithubParam 9132032 131 ns/op 0 B/op 0 allocs/op -BenchmarkGocraftWeb_GithubParam 1000000 1446 ns/op 712 B/op 9 allocs/op -BenchmarkGoji_GithubParam 1248640 977 ns/op 336 B/op 2 allocs/op -BenchmarkGojiv2_GithubParam 383233 2784 ns/op 1408 B/op 13 allocs/op -BenchmarkGoJsonRest_GithubParam 1000000 1991 ns/op 713 B/op 14 allocs/op -BenchmarkGoRestful_GithubParam 76414 16015 ns/op 4352 B/op 16 allocs/op -BenchmarkGorillaMux_GithubParam 150026 7663 ns/op 1296 B/op 10 allocs/op -BenchmarkGowwwRouter_GithubParam 1592044 751 ns/op 432 B/op 3 allocs/op -BenchmarkHttpRouter_GithubParam 10420628 115 ns/op 0 B/op 0 allocs/op -BenchmarkHttpTreeMux_GithubParam 1403755 835 ns/op 384 B/op 4 allocs/op -BenchmarkKocha_GithubParam 2286170 533 ns/op 128 B/op 5 allocs/op -BenchmarkLARS_GithubParam 9540374 129 ns/op 0 B/op 0 allocs/op -BenchmarkMacaron_GithubParam 533154 2742 ns/op 1072 B/op 10 allocs/op -BenchmarkMartini_GithubParam 119397 9638 ns/op 1152 B/op 11 allocs/op -BenchmarkPat_GithubParam 150675 8858 ns/op 2408 B/op 48 allocs/op -BenchmarkPossum_GithubParam 1000000 1001 ns/op 496 B/op 5 allocs/op -BenchmarkR2router_GithubParam 1602886 761 ns/op 432 B/op 5 allocs/op -BenchmarkRivet_GithubParam 2986579 409 ns/op 96 B/op 1 allocs/op -BenchmarkTango_GithubParam 1000000 1356 ns/op 344 B/op 8 allocs/op -BenchmarkTigerTonic_GithubParam 388899 3429 ns/op 1176 B/op 22 allocs/op -BenchmarkTraffic_GithubParam 123160 9734 ns/op 2816 B/op 40 allocs/op -BenchmarkVulcan_GithubParam 1000000 1138 ns/op 98 B/op 3 allocs/op -BenchmarkAce_GithubAll 40543 29670 ns/op 0 B/op 0 allocs/op -BenchmarkAero_GithubAll 57632 20648 ns/op 0 B/op 0 allocs/op -BenchmarkBear_GithubAll 9234 216179 ns/op 86448 B/op 943 allocs/op -BenchmarkBeego_GithubAll 7407 243496 ns/op 71456 B/op 609 allocs/op -BenchmarkBone_GithubAll 420 2922835 ns/op 720160 B/op 8620 allocs/op -BenchmarkChi_GithubAll 7620 238331 ns/op 87696 B/op 609 allocs/op -BenchmarkDenco_GithubAll 18355 64494 ns/op 20224 B/op 167 allocs/op -BenchmarkEcho_GithubAll 31251 38479 ns/op 0 B/op 0 allocs/op -BenchmarkGin_GithubAll 43550 27364 ns/op 0 B/op 0 allocs/op -BenchmarkGocraftWeb_GithubAll 4117 300062 ns/op 131656 B/op 1686 allocs/op -BenchmarkGoji_GithubAll 3274 416158 ns/op 56112 B/op 334 allocs/op -BenchmarkGojiv2_GithubAll 1402 870518 ns/op 352720 B/op 4321 allocs/op -BenchmarkGoJsonRest_GithubAll 2976 401507 ns/op 134371 B/op 2737 allocs/op -BenchmarkGoRestful_GithubAll 410 2913158 ns/op 910144 B/op 2938 allocs/op -BenchmarkGorillaMux_GithubAll 346 3384987 ns/op 251650 B/op 1994 allocs/op -BenchmarkGowwwRouter_GithubAll 10000 143025 ns/op 72144 B/op 501 allocs/op -BenchmarkHttpRouter_GithubAll 55938 21360 ns/op 0 B/op 0 allocs/op -BenchmarkHttpTreeMux_GithubAll 10000 153944 ns/op 65856 B/op 671 allocs/op -BenchmarkKocha_GithubAll 10000 106315 ns/op 23304 B/op 843 allocs/op -BenchmarkLARS_GithubAll 47779 25084 ns/op 0 B/op 0 allocs/op -BenchmarkMacaron_GithubAll 3266 371907 ns/op 149409 B/op 1624 allocs/op -BenchmarkMartini_GithubAll 331 3444706 ns/op 226551 B/op 2325 allocs/op -BenchmarkPat_GithubAll 273 4381818 ns/op 1483152 B/op 26963 allocs/op -BenchmarkPossum_GithubAll 10000 164367 ns/op 84448 B/op 609 allocs/op -BenchmarkR2router_GithubAll 10000 160220 ns/op 77328 B/op 979 allocs/op -BenchmarkRivet_GithubAll 14625 82453 ns/op 16272 B/op 167 allocs/op -BenchmarkTango_GithubAll 6255 279611 ns/op 63826 B/op 1618 allocs/op -BenchmarkTigerTonic_GithubAll 2008 687874 ns/op 193856 B/op 4474 allocs/op -BenchmarkTraffic_GithubAll 355 3478508 ns/op 820744 B/op 14114 allocs/op -BenchmarkVulcan_GithubAll 6885 193333 ns/op 19894 B/op 609 allocs/op +``` +BenchmarkGin_Param5 30261015 38.89 ns/op 0 B/op 0 allocs/op +BenchmarkAce_Param5 11764478 100.2 ns/op 160 B/op 1 allocs/op +BenchmarkAero_Param5 33756498 34.24 ns/op 0 B/op 0 allocs/op +BenchmarkBear_Param5 3066855 387.5 ns/op 501 B/op 5 allocs/op +BenchmarkBeego_Param5 2459563 495.6 ns/op 352 B/op 3 allocs/op +BenchmarkBone_Param5 1000000 1042 ns/op 1232 B/op 10 allocs/op +BenchmarkChi_Param5 2523159 469.0 ns/op 704 B/op 4 allocs/op +BenchmarkDenco_Param5 8588504 130.9 ns/op 160 B/op 1 allocs/op +BenchmarkEcho_Param5 22098444 49.58 ns/op 0 B/op 0 allocs/op +BenchmarkGocraftWeb_Param5 2255988 522.1 ns/op 920 B/op 11 allocs/op +BenchmarkGoji_Param5 4107170 283.3 ns/op 336 B/op 2 allocs/op +BenchmarkGojiv2_Param5 1691694 706.7 ns/op 1248 B/op 10 allocs/op +BenchmarkGoJsonRest_Param5 1579816 736.0 ns/op 1073 B/op 16 allocs/op +BenchmarkGoRestful_Param5 495588 2283 ns/op 5400 B/op 15 allocs/op +BenchmarkGorillaMux_Param5 734078 1488 ns/op 1184 B/op 8 allocs/op +BenchmarkGowwwRouter_Param5 7023253 171.0 ns/op 368 B/op 2 allocs/op +BenchmarkHttpRouter_Param5 16128580 71.82 ns/op 160 B/op 1 allocs/op +BenchmarkHttpTreeMux_Param5 2799802 421.4 ns/op 576 B/op 6 allocs/op +BenchmarkKocha_Param5 5397548 216.4 ns/op 304 B/op 6 allocs/op +BenchmarkLARS_Param5 31268811 38.98 ns/op 0 B/op 0 allocs/op +BenchmarkMacaron_Param5 1246534 934.2 ns/op 1064 B/op 10 allocs/op +BenchmarkMartini_Param5 523628 2384 ns/op 1256 B/op 13 allocs/op +BenchmarkPat_Param5 726936 1592 ns/op 944 B/op 32 allocs/op +BenchmarkPossum_Param5 3320758 356.0 ns/op 496 B/op 5 allocs/op +BenchmarkR2router_Param5 3726697 312.7 ns/op 432 B/op 5 allocs/op +BenchmarkRivet_Param5 8050082 145.0 ns/op 240 B/op 1 allocs/op +BenchmarkTango_Param5 3265436 366.0 ns/op 392 B/op 6 allocs/op +BenchmarkTigerTonic_Param5 469060 2632 ns/op 2408 B/op 41 allocs/op +BenchmarkTraffic_Param5 425434 2722 ns/op 2280 B/op 31 allocs/op +BenchmarkVulcan_Param5 5213118 241.1 ns/op 98 B/op 3 allocs/op ``` -## Google+ +### 20 Parameters -```sh -BenchmarkGin_GPlusStatic 19247326 62.2 ns/op 0 B/op 0 allocs/op - -BenchmarkAce_GPlusStatic 20235060 59.2 ns/op 0 B/op 0 allocs/op -BenchmarkAero_GPlusStatic 31978935 37.6 ns/op 0 B/op 0 allocs/op -BenchmarkBear_GPlusStatic 3516523 341 ns/op 104 B/op 3 allocs/op -BenchmarkBeego_GPlusStatic 1212036 991 ns/op 352 B/op 3 allocs/op -BenchmarkBone_GPlusStatic 6736242 183 ns/op 32 B/op 1 allocs/op -BenchmarkChi_GPlusStatic 1490640 814 ns/op 432 B/op 3 allocs/op -BenchmarkDenco_GPlusStatic 55006856 21.8 ns/op 0 B/op 0 allocs/op -BenchmarkEcho_GPlusStatic 17688258 67.9 ns/op 0 B/op 0 allocs/op -BenchmarkGocraftWeb_GPlusStatic 1829181 666 ns/op 280 B/op 5 allocs/op -BenchmarkGoji_GPlusStatic 9147451 130 ns/op 0 B/op 0 allocs/op -BenchmarkGojiv2_GPlusStatic 594015 2063 ns/op 1312 B/op 10 allocs/op -BenchmarkGoJsonRest_GPlusStatic 1264906 950 ns/op 329 B/op 11 allocs/op -BenchmarkGoRestful_GPlusStatic 231558 5341 ns/op 3872 B/op 13 allocs/op -BenchmarkGorillaMux_GPlusStatic 908418 1809 ns/op 976 B/op 9 allocs/op -BenchmarkGowwwRouter_GPlusStatic 40684604 29.5 ns/op 0 B/op 0 allocs/op -BenchmarkHttpRouter_GPlusStatic 46742804 25.7 ns/op 0 B/op 0 allocs/op -BenchmarkHttpTreeMux_GPlusStatic 32567161 36.9 ns/op 0 B/op 0 allocs/op -BenchmarkKocha_GPlusStatic 33800060 35.3 ns/op 0 B/op 0 allocs/op -BenchmarkLARS_GPlusStatic 20431858 60.0 ns/op 0 B/op 0 allocs/op -BenchmarkMacaron_GPlusStatic 1000000 1745 ns/op 736 B/op 8 allocs/op -BenchmarkMartini_GPlusStatic 442248 3619 ns/op 768 B/op 9 allocs/op -BenchmarkPat_GPlusStatic 4328004 292 ns/op 96 B/op 2 allocs/op -BenchmarkPossum_GPlusStatic 1570753 763 ns/op 416 B/op 3 allocs/op -BenchmarkR2router_GPlusStatic 3339474 355 ns/op 144 B/op 4 allocs/op -BenchmarkRivet_GPlusStatic 18570961 64.7 ns/op 0 B/op 0 allocs/op -BenchmarkTango_GPlusStatic 1388702 860 ns/op 200 B/op 8 allocs/op -BenchmarkTigerTonic_GPlusStatic 7803543 159 ns/op 32 B/op 1 allocs/op -BenchmarkTraffic_GPlusStatic 878605 2171 ns/op 1112 B/op 16 allocs/op -BenchmarkVulcan_GPlusStatic 2742446 437 ns/op 98 B/op 3 allocs/op -BenchmarkAce_GPlusParam 11626975 105 ns/op 0 B/op 0 allocs/op -BenchmarkAero_GPlusParam 16914322 71.6 ns/op 0 B/op 0 allocs/op -BenchmarkBear_GPlusParam 1405173 832 ns/op 480 B/op 5 allocs/op -BenchmarkBeego_GPlusParam 1000000 1075 ns/op 352 B/op 3 allocs/op -BenchmarkBone_GPlusParam 1000000 1557 ns/op 816 B/op 6 allocs/op -BenchmarkChi_GPlusParam 1347926 894 ns/op 432 B/op 3 allocs/op -BenchmarkDenco_GPlusParam 5513000 212 ns/op 64 B/op 1 allocs/op -BenchmarkEcho_GPlusParam 11884383 101 ns/op 0 B/op 0 allocs/op -BenchmarkGin_GPlusParam 12898952 93.1 ns/op 0 B/op 0 allocs/op -BenchmarkGocraftWeb_GPlusParam 1000000 1194 ns/op 648 B/op 8 allocs/op -BenchmarkGoji_GPlusParam 1857229 645 ns/op 336 B/op 2 allocs/op -BenchmarkGojiv2_GPlusParam 520939 2322 ns/op 1328 B/op 11 allocs/op -BenchmarkGoJsonRest_GPlusParam 1000000 1536 ns/op 649 B/op 13 allocs/op -BenchmarkGoRestful_GPlusParam 205449 5800 ns/op 4192 B/op 14 allocs/op -BenchmarkGorillaMux_GPlusParam 395310 3188 ns/op 1280 B/op 10 allocs/op -BenchmarkGowwwRouter_GPlusParam 1851798 667 ns/op 432 B/op 3 allocs/op -BenchmarkHttpRouter_GPlusParam 18420789 65.2 ns/op 0 B/op 0 allocs/op -BenchmarkHttpTreeMux_GPlusParam 1878463 629 ns/op 352 B/op 3 allocs/op -BenchmarkKocha_GPlusParam 4495610 273 ns/op 56 B/op 3 allocs/op -BenchmarkLARS_GPlusParam 14615976 83.2 ns/op 0 B/op 0 allocs/op -BenchmarkMacaron_GPlusParam 584145 2549 ns/op 1072 B/op 10 allocs/op -BenchmarkMartini_GPlusParam 250501 4583 ns/op 1072 B/op 10 allocs/op -BenchmarkPat_GPlusParam 1000000 1645 ns/op 576 B/op 11 allocs/op -BenchmarkPossum_GPlusParam 1000000 1008 ns/op 496 B/op 5 allocs/op -BenchmarkR2router_GPlusParam 1708191 688 ns/op 432 B/op 5 allocs/op -BenchmarkRivet_GPlusParam 5795014 211 ns/op 48 B/op 1 allocs/op -BenchmarkTango_GPlusParam 1000000 1091 ns/op 264 B/op 8 allocs/op -BenchmarkTigerTonic_GPlusParam 760221 2489 ns/op 856 B/op 16 allocs/op -BenchmarkTraffic_GPlusParam 309774 4039 ns/op 1872 B/op 21 allocs/op -BenchmarkVulcan_GPlusParam 1935730 623 ns/op 98 B/op 3 allocs/op -BenchmarkAce_GPlus2Params 9158314 134 ns/op 0 B/op 0 allocs/op -BenchmarkAero_GPlus2Params 11300517 107 ns/op 0 B/op 0 allocs/op -BenchmarkBear_GPlus2Params 1239238 961 ns/op 496 B/op 5 allocs/op -BenchmarkBeego_GPlus2Params 1000000 1202 ns/op 352 B/op 3 allocs/op -BenchmarkBone_GPlus2Params 335576 3725 ns/op 1168 B/op 10 allocs/op -BenchmarkChi_GPlus2Params 1000000 1014 ns/op 432 B/op 3 allocs/op -BenchmarkDenco_GPlus2Params 4394598 280 ns/op 64 B/op 1 allocs/op -BenchmarkEcho_GPlus2Params 7851861 154 ns/op 0 B/op 0 allocs/op -BenchmarkGin_GPlus2Params 9958588 120 ns/op 0 B/op 0 allocs/op -BenchmarkGocraftWeb_GPlus2Params 1000000 1433 ns/op 712 B/op 9 allocs/op -BenchmarkGoji_GPlus2Params 1325134 909 ns/op 336 B/op 2 allocs/op -BenchmarkGojiv2_GPlus2Params 405955 2870 ns/op 1408 B/op 14 allocs/op -BenchmarkGoJsonRest_GPlus2Params 977038 1987 ns/op 713 B/op 14 allocs/op -BenchmarkGoRestful_GPlus2Params 205018 6142 ns/op 4384 B/op 16 allocs/op -BenchmarkGorillaMux_GPlus2Params 205641 6015 ns/op 1296 B/op 10 allocs/op -BenchmarkGowwwRouter_GPlus2Params 1748542 684 ns/op 432 B/op 3 allocs/op -BenchmarkHttpRouter_GPlus2Params 14047102 87.7 ns/op 0 B/op 0 allocs/op -BenchmarkHttpTreeMux_GPlus2Params 1418673 828 ns/op 384 B/op 4 allocs/op -BenchmarkKocha_GPlus2Params 2334562 520 ns/op 128 B/op 5 allocs/op -BenchmarkLARS_GPlus2Params 11954094 101 ns/op 0 B/op 0 allocs/op -BenchmarkMacaron_GPlus2Params 491552 2890 ns/op 1072 B/op 10 allocs/op -BenchmarkMartini_GPlus2Params 120532 9545 ns/op 1200 B/op 13 allocs/op -BenchmarkPat_GPlus2Params 194739 6766 ns/op 2168 B/op 33 allocs/op -BenchmarkPossum_GPlus2Params 1201224 1009 ns/op 496 B/op 5 allocs/op -BenchmarkR2router_GPlus2Params 1575535 756 ns/op 432 B/op 5 allocs/op -BenchmarkRivet_GPlus2Params 3698930 325 ns/op 96 B/op 1 allocs/op -BenchmarkTango_GPlus2Params 1000000 1212 ns/op 344 B/op 8 allocs/op -BenchmarkTigerTonic_GPlus2Params 349350 3660 ns/op 1200 B/op 22 allocs/op -BenchmarkTraffic_GPlus2Params 169714 7862 ns/op 2248 B/op 28 allocs/op -BenchmarkVulcan_GPlus2Params 1222288 974 ns/op 98 B/op 3 allocs/op -BenchmarkAce_GPlusAll 845606 1398 ns/op 0 B/op 0 allocs/op -BenchmarkAero_GPlusAll 1000000 1009 ns/op 0 B/op 0 allocs/op -BenchmarkBear_GPlusAll 103830 11386 ns/op 5488 B/op 61 allocs/op -BenchmarkBeego_GPlusAll 82653 14784 ns/op 4576 B/op 39 allocs/op -BenchmarkBone_GPlusAll 36601 33123 ns/op 11744 B/op 109 allocs/op -BenchmarkChi_GPlusAll 95264 12831 ns/op 5616 B/op 39 allocs/op -BenchmarkDenco_GPlusAll 567681 2950 ns/op 672 B/op 11 allocs/op -BenchmarkEcho_GPlusAll 720366 1665 ns/op 0 B/op 0 allocs/op -BenchmarkGin_GPlusAll 1000000 1185 ns/op 0 B/op 0 allocs/op -BenchmarkGocraftWeb_GPlusAll 71575 16365 ns/op 8040 B/op 103 allocs/op -BenchmarkGoji_GPlusAll 136352 9191 ns/op 3696 B/op 22 allocs/op -BenchmarkGojiv2_GPlusAll 38006 31802 ns/op 17616 B/op 154 allocs/op -BenchmarkGoJsonRest_GPlusAll 57238 21561 ns/op 8117 B/op 170 allocs/op -BenchmarkGoRestful_GPlusAll 15147 79276 ns/op 55520 B/op 192 allocs/op -BenchmarkGorillaMux_GPlusAll 24446 48410 ns/op 16112 B/op 128 allocs/op -BenchmarkGowwwRouter_GPlusAll 150112 7770 ns/op 4752 B/op 33 allocs/op -BenchmarkHttpRouter_GPlusAll 1367820 878 ns/op 0 B/op 0 allocs/op -BenchmarkHttpTreeMux_GPlusAll 166628 8004 ns/op 4032 B/op 38 allocs/op -BenchmarkKocha_GPlusAll 265694 4570 ns/op 976 B/op 43 allocs/op -BenchmarkLARS_GPlusAll 1000000 1068 ns/op 0 B/op 0 allocs/op -BenchmarkMacaron_GPlusAll 54564 23305 ns/op 9568 B/op 104 allocs/op -BenchmarkMartini_GPlusAll 16274 73845 ns/op 14016 B/op 145 allocs/op -BenchmarkPat_GPlusAll 27181 44478 ns/op 15264 B/op 271 allocs/op -BenchmarkPossum_GPlusAll 122587 10277 ns/op 5408 B/op 39 allocs/op -BenchmarkR2router_GPlusAll 130137 9297 ns/op 5040 B/op 63 allocs/op -BenchmarkRivet_GPlusAll 532438 3323 ns/op 768 B/op 11 allocs/op -BenchmarkTango_GPlusAll 86054 14531 ns/op 3656 B/op 104 allocs/op -BenchmarkTigerTonic_GPlusAll 33936 35356 ns/op 11600 B/op 242 allocs/op -BenchmarkTraffic_GPlusAll 17833 68181 ns/op 26248 B/op 341 allocs/op -BenchmarkVulcan_GPlusAll 120109 9861 ns/op 1274 B/op 39 allocs/op +``` +BenchmarkGin_Param20 13291521 89.03 ns/op 0 B/op 0 allocs/op +BenchmarkAce_Param20 4432400 265.2 ns/op 640 B/op 1 allocs/op +BenchmarkAero_Param20 10534245 111.3 ns/op 0 B/op 0 allocs/op +BenchmarkBear_Param20 1000000 1027 ns/op 1665 B/op 5 allocs/op +BenchmarkBeego_Param20 1398088 856.2 ns/op 352 B/op 3 allocs/op +BenchmarkBone_Param20 275770 4416 ns/op 4368 B/op 32 allocs/op +BenchmarkChi_Param20 1000000 1111 ns/op 704 B/op 4 allocs/op +BenchmarkDenco_Param20 2717076 430.2 ns/op 640 B/op 1 allocs/op +BenchmarkEcho_Param20 7671782 152.3 ns/op 0 B/op 0 allocs/op +BenchmarkGocraftWeb_Param20 672906 1633 ns/op 3795 B/op 15 allocs/op +BenchmarkGoji_Param20 1000000 1001 ns/op 1247 B/op 2 allocs/op +BenchmarkGojiv2_Param20 760102 1528 ns/op 1568 B/op 12 allocs/op +BenchmarkGoJsonRest_Param20 516908 2099 ns/op 3539 B/op 24 allocs/op +BenchmarkGoRestful_Param20 196784 5920 ns/op 8520 B/op 15 allocs/op +BenchmarkGorillaMux_Param20 307082 3793 ns/op 3483 B/op 10 allocs/op +BenchmarkGowwwRouter_Param20 5098538 254.1 ns/op 368 B/op 2 allocs/op +BenchmarkHttpRouter_Param20 5192563 230.2 ns/op 640 B/op 1 allocs/op +BenchmarkHttpTreeMux_Param20 471916 3085 ns/op 3168 B/op 10 allocs/op +BenchmarkKocha_Param20 1429558 831.6 ns/op 1264 B/op 12 allocs/op +BenchmarkLARS_Param20 13176316 90.49 ns/op 0 B/op 0 allocs/op +BenchmarkMacaron_Param20 498850 2459 ns/op 2680 B/op 12 allocs/op +BenchmarkMartini_Param20 124274 10258 ns/op 3668 B/op 15 allocs/op +BenchmarkPat_Param20 454987 2592 ns/op 1640 B/op 44 allocs/op +BenchmarkPossum_Param20 3251416 383.8 ns/op 496 B/op 5 allocs/op +BenchmarkR2router_Param20 908521 1291 ns/op 2176 B/op 7 allocs/op +BenchmarkRivet_Param20 1000000 1027 ns/op 1024 B/op 1 allocs/op +BenchmarkTango_Param20 992810 1123 ns/op 952 B/op 6 allocs/op +BenchmarkTigerTonic_Param20 121791 9949 ns/op 10248 B/op 111 allocs/op +BenchmarkTraffic_Param20 119523 10037 ns/op 7784 B/op 56 allocs/op +BenchmarkVulcan_Param20 2427007 504.5 ns/op 98 B/op 3 allocs/op ``` -## Parse.com +### Param Write -```sh -BenchmarkGin_ParseStatic 18877833 63.5 ns/op 0 B/op 0 allocs/op - -BenchmarkAce_ParseStatic 19663731 60.8 ns/op 0 B/op 0 allocs/op -BenchmarkAero_ParseStatic 28967341 41.5 ns/op 0 B/op 0 allocs/op -BenchmarkBear_ParseStatic 3006984 402 ns/op 120 B/op 3 allocs/op -BenchmarkBeego_ParseStatic 1000000 1031 ns/op 352 B/op 3 allocs/op -BenchmarkBone_ParseStatic 1782482 675 ns/op 144 B/op 3 allocs/op -BenchmarkChi_ParseStatic 1453261 819 ns/op 432 B/op 3 allocs/op -BenchmarkDenco_ParseStatic 45023595 26.5 ns/op 0 B/op 0 allocs/op -BenchmarkEcho_ParseStatic 17330470 69.3 ns/op 0 B/op 0 allocs/op -BenchmarkGocraftWeb_ParseStatic 1644006 731 ns/op 296 B/op 5 allocs/op -BenchmarkGoji_ParseStatic 7026930 170 ns/op 0 B/op 0 allocs/op -BenchmarkGojiv2_ParseStatic 517618 2037 ns/op 1312 B/op 10 allocs/op -BenchmarkGoJsonRest_ParseStatic 1227080 975 ns/op 329 B/op 11 allocs/op -BenchmarkGoRestful_ParseStatic 192458 6659 ns/op 4256 B/op 13 allocs/op -BenchmarkGorillaMux_ParseStatic 744062 2109 ns/op 976 B/op 9 allocs/op -BenchmarkGowwwRouter_ParseStatic 37781062 31.8 ns/op 0 B/op 0 allocs/op -BenchmarkHttpRouter_ParseStatic 45311223 26.5 ns/op 0 B/op 0 allocs/op -BenchmarkHttpTreeMux_ParseStatic 21383475 56.1 ns/op 0 B/op 0 allocs/op -BenchmarkKocha_ParseStatic 29953290 40.1 ns/op 0 B/op 0 allocs/op -BenchmarkLARS_ParseStatic 20036196 62.7 ns/op 0 B/op 0 allocs/op -BenchmarkMacaron_ParseStatic 1000000 1740 ns/op 736 B/op 8 allocs/op -BenchmarkMartini_ParseStatic 404156 3801 ns/op 768 B/op 9 allocs/op -BenchmarkPat_ParseStatic 1547180 772 ns/op 240 B/op 5 allocs/op -BenchmarkPossum_ParseStatic 1608991 757 ns/op 416 B/op 3 allocs/op -BenchmarkR2router_ParseStatic 3177936 385 ns/op 144 B/op 4 allocs/op -BenchmarkRivet_ParseStatic 17783205 67.4 ns/op 0 B/op 0 allocs/op -BenchmarkTango_ParseStatic 1210777 990 ns/op 248 B/op 8 allocs/op -BenchmarkTigerTonic_ParseStatic 5316440 231 ns/op 48 B/op 1 allocs/op -BenchmarkTraffic_ParseStatic 496050 2539 ns/op 1256 B/op 19 allocs/op -BenchmarkVulcan_ParseStatic 2462798 488 ns/op 98 B/op 3 allocs/op -BenchmarkAce_ParseParam 13393669 89.6 ns/op 0 B/op 0 allocs/op -BenchmarkAero_ParseParam 19836619 60.4 ns/op 0 B/op 0 allocs/op -BenchmarkBear_ParseParam 1405954 864 ns/op 467 B/op 5 allocs/op -BenchmarkBeego_ParseParam 1000000 1065 ns/op 352 B/op 3 allocs/op -BenchmarkBone_ParseParam 1000000 1698 ns/op 896 B/op 7 allocs/op -BenchmarkChi_ParseParam 1356037 873 ns/op 432 B/op 3 allocs/op -BenchmarkDenco_ParseParam 6241392 204 ns/op 64 B/op 1 allocs/op -BenchmarkEcho_ParseParam 14088100 85.1 ns/op 0 B/op 0 allocs/op -BenchmarkGin_ParseParam 17426064 68.9 ns/op 0 B/op 0 allocs/op -BenchmarkGocraftWeb_ParseParam 1000000 1254 ns/op 664 B/op 8 allocs/op -BenchmarkGoji_ParseParam 1682574 713 ns/op 336 B/op 2 allocs/op -BenchmarkGojiv2_ParseParam 502224 2333 ns/op 1360 B/op 12 allocs/op -BenchmarkGoJsonRest_ParseParam 1000000 1401 ns/op 649 B/op 13 allocs/op -BenchmarkGoRestful_ParseParam 182623 7097 ns/op 4576 B/op 14 allocs/op -BenchmarkGorillaMux_ParseParam 482332 2477 ns/op 1280 B/op 10 allocs/op -BenchmarkGowwwRouter_ParseParam 1834873 657 ns/op 432 B/op 3 allocs/op -BenchmarkHttpRouter_ParseParam 23593393 51.0 ns/op 0 B/op 0 allocs/op -BenchmarkHttpTreeMux_ParseParam 2100160 574 ns/op 352 B/op 3 allocs/op -BenchmarkKocha_ParseParam 4837220 252 ns/op 56 B/op 3 allocs/op -BenchmarkLARS_ParseParam 18411192 66.2 ns/op 0 B/op 0 allocs/op -BenchmarkMacaron_ParseParam 571870 2398 ns/op 1072 B/op 10 allocs/op -BenchmarkMartini_ParseParam 286262 4268 ns/op 1072 B/op 10 allocs/op -BenchmarkPat_ParseParam 692906 2157 ns/op 992 B/op 15 allocs/op -BenchmarkPossum_ParseParam 1000000 1011 ns/op 496 B/op 5 allocs/op -BenchmarkR2router_ParseParam 1722735 697 ns/op 432 B/op 5 allocs/op -BenchmarkRivet_ParseParam 6058054 203 ns/op 48 B/op 1 allocs/op -BenchmarkTango_ParseParam 1000000 1061 ns/op 280 B/op 8 allocs/op -BenchmarkTigerTonic_ParseParam 890275 2277 ns/op 784 B/op 15 allocs/op -BenchmarkTraffic_ParseParam 351322 3543 ns/op 1896 B/op 21 allocs/op -BenchmarkVulcan_ParseParam 2076544 572 ns/op 98 B/op 3 allocs/op -BenchmarkAce_Parse2Params 11718074 101 ns/op 0 B/op 0 allocs/op -BenchmarkAero_Parse2Params 16264988 73.4 ns/op 0 B/op 0 allocs/op -BenchmarkBear_Parse2Params 1238322 973 ns/op 496 B/op 5 allocs/op -BenchmarkBeego_Parse2Params 1000000 1120 ns/op 352 B/op 3 allocs/op -BenchmarkBone_Parse2Params 1000000 1632 ns/op 848 B/op 6 allocs/op -BenchmarkChi_Parse2Params 1239477 955 ns/op 432 B/op 3 allocs/op -BenchmarkDenco_Parse2Params 4944133 245 ns/op 64 B/op 1 allocs/op -BenchmarkEcho_Parse2Params 10518286 114 ns/op 0 B/op 0 allocs/op -BenchmarkGin_Parse2Params 14505195 82.7 ns/op 0 B/op 0 allocs/op -BenchmarkGocraftWeb_Parse2Params 1000000 1437 ns/op 712 B/op 9 allocs/op -BenchmarkGoji_Parse2Params 1689883 707 ns/op 336 B/op 2 allocs/op -BenchmarkGojiv2_Parse2Params 502334 2308 ns/op 1344 B/op 11 allocs/op -BenchmarkGoJsonRest_Parse2Params 1000000 1771 ns/op 713 B/op 14 allocs/op -BenchmarkGoRestful_Parse2Params 159092 7583 ns/op 4928 B/op 14 allocs/op -BenchmarkGorillaMux_Parse2Params 417548 2980 ns/op 1296 B/op 10 allocs/op -BenchmarkGowwwRouter_Parse2Params 1751737 686 ns/op 432 B/op 3 allocs/op -BenchmarkHttpRouter_Parse2Params 18089204 66.3 ns/op 0 B/op 0 allocs/op -BenchmarkHttpTreeMux_Parse2Params 1556986 777 ns/op 384 B/op 4 allocs/op -BenchmarkKocha_Parse2Params 2493082 485 ns/op 128 B/op 5 allocs/op -BenchmarkLARS_Parse2Params 15350108 78.5 ns/op 0 B/op 0 allocs/op -BenchmarkMacaron_Parse2Params 530974 2605 ns/op 1072 B/op 10 allocs/op -BenchmarkMartini_Parse2Params 247069 4673 ns/op 1152 B/op 11 allocs/op -BenchmarkPat_Parse2Params 816295 2126 ns/op 752 B/op 16 allocs/op -BenchmarkPossum_Parse2Params 1000000 1002 ns/op 496 B/op 5 allocs/op -BenchmarkR2router_Parse2Params 1569771 733 ns/op 432 B/op 5 allocs/op -BenchmarkRivet_Parse2Params 4080546 295 ns/op 96 B/op 1 allocs/op -BenchmarkTango_Parse2Params 1000000 1121 ns/op 312 B/op 8 allocs/op -BenchmarkTigerTonic_Parse2Params 399556 3470 ns/op 1168 B/op 22 allocs/op -BenchmarkTraffic_Parse2Params 314194 4159 ns/op 1944 B/op 22 allocs/op -BenchmarkVulcan_Parse2Params 1827559 664 ns/op 98 B/op 3 allocs/op -BenchmarkAce_ParseAll 478395 2503 ns/op 0 B/op 0 allocs/op -BenchmarkAero_ParseAll 715392 1658 ns/op 0 B/op 0 allocs/op -BenchmarkBear_ParseAll 59191 20124 ns/op 8928 B/op 110 allocs/op -BenchmarkBeego_ParseAll 45507 27266 ns/op 9152 B/op 78 allocs/op -BenchmarkBone_ParseAll 29328 41459 ns/op 16208 B/op 147 allocs/op -BenchmarkChi_ParseAll 48531 25053 ns/op 11232 B/op 78 allocs/op -BenchmarkDenco_ParseAll 325532 4284 ns/op 928 B/op 16 allocs/op -BenchmarkEcho_ParseAll 433771 2759 ns/op 0 B/op 0 allocs/op -BenchmarkGin_ParseAll 576316 2082 ns/op 0 B/op 0 allocs/op -BenchmarkGocraftWeb_ParseAll 41500 29692 ns/op 13728 B/op 181 allocs/op -BenchmarkGoji_ParseAll 80833 15563 ns/op 5376 B/op 32 allocs/op -BenchmarkGojiv2_ParseAll 19836 60335 ns/op 34448 B/op 277 allocs/op -BenchmarkGoJsonRest_ParseAll 32210 38027 ns/op 13866 B/op 321 allocs/op -BenchmarkGoRestful_ParseAll 6644 190842 ns/op 117600 B/op 354 allocs/op -BenchmarkGorillaMux_ParseAll 12634 95894 ns/op 30288 B/op 250 allocs/op -BenchmarkGowwwRouter_ParseAll 98152 12159 ns/op 6912 B/op 48 allocs/op -BenchmarkHttpRouter_ParseAll 933208 1273 ns/op 0 B/op 0 allocs/op -BenchmarkHttpTreeMux_ParseAll 107191 11554 ns/op 5728 B/op 51 allocs/op -BenchmarkKocha_ParseAll 184862 6225 ns/op 1112 B/op 54 allocs/op -BenchmarkLARS_ParseAll 644546 1858 ns/op 0 B/op 0 allocs/op -BenchmarkMacaron_ParseAll 26145 46484 ns/op 19136 B/op 208 allocs/op -BenchmarkMartini_ParseAll 10000 121838 ns/op 25072 B/op 253 allocs/op -BenchmarkPat_ParseAll 25417 47196 ns/op 15216 B/op 308 allocs/op -BenchmarkPossum_ParseAll 58550 20735 ns/op 10816 B/op 78 allocs/op -BenchmarkR2router_ParseAll 72732 16584 ns/op 8352 B/op 120 allocs/op -BenchmarkRivet_ParseAll 281365 4968 ns/op 912 B/op 16 allocs/op -BenchmarkTango_ParseAll 42831 28668 ns/op 7168 B/op 208 allocs/op -BenchmarkTigerTonic_ParseAll 23774 49972 ns/op 16048 B/op 332 allocs/op -BenchmarkTraffic_ParseAll 10000 104679 ns/op 45520 B/op 605 allocs/op -BenchmarkVulcan_ParseAll 64810 18108 ns/op 2548 B/op 78 allocs/op +``` +BenchmarkGin_ParamWrite 23316990 50.84 ns/op 0 B/op 0 allocs/op +BenchmarkAce_ParamWrite 13474160 92.09 ns/op 40 B/op 2 allocs/op +BenchmarkAero_ParamWrite 34476930 33.00 ns/op 0 B/op 0 allocs/op +BenchmarkBear_ParamWrite 3806036 310.0 ns/op 456 B/op 5 allocs/op +BenchmarkBeego_ParamWrite 2834390 419.9 ns/op 360 B/op 4 allocs/op +BenchmarkBone_ParamWrite 2627498 466.8 ns/op 752 B/op 5 allocs/op +BenchmarkChi_ParamWrite 3128284 371.5 ns/op 704 B/op 4 allocs/op +BenchmarkDenco_ParamWrite 16741923 71.49 ns/op 32 B/op 1 allocs/op +BenchmarkEcho_ParamWrite 29455958 37.94 ns/op 8 B/op 1 allocs/op +BenchmarkGocraftWeb_ParamWrite 2992538 393.9 ns/op 648 B/op 8 allocs/op +BenchmarkGoji_ParamWrite 4816736 250.7 ns/op 336 B/op 2 allocs/op +BenchmarkGojiv2_ParamWrite 2044604 590.6 ns/op 1152 B/op 9 allocs/op +BenchmarkGoJsonRest_ParamWrite 2149220 544.9 ns/op 1064 B/op 18 allocs/op +BenchmarkGoRestful_ParamWrite 633780 1853 ns/op 4616 B/op 16 allocs/op +BenchmarkGorillaMux_ParamWrite 1652036 727.3 ns/op 1160 B/op 9 allocs/op +BenchmarkGowwwRouter_ParamWrite 4195808 279.1 ns/op 392 B/op 3 allocs/op +BenchmarkHttpRouter_ParamWrite 21606003 54.14 ns/op 32 B/op 1 allocs/op +BenchmarkHttpTreeMux_ParamWrite 5398851 224.9 ns/op 352 B/op 3 allocs/op +BenchmarkKocha_ParamWrite 14068706 83.18 ns/op 48 B/op 2 allocs/op +BenchmarkLARS_ParamWrite 25768928 47.62 ns/op 0 B/op 0 allocs/op +BenchmarkMacaron_ParamWrite 1355762 894.2 ns/op 1152 B/op 13 allocs/op +BenchmarkMartini_ParamWrite 514706 2544 ns/op 1224 B/op 16 allocs/op +BenchmarkPat_ParamWrite 1285564 880.5 ns/op 1040 B/op 17 allocs/op +BenchmarkPossum_ParamWrite 3127676 383.7 ns/op 496 B/op 5 allocs/op +BenchmarkR2router_ParamWrite 4948783 234.5 ns/op 400 B/op 4 allocs/op +BenchmarkRivet_ParamWrite 9561326 125.0 ns/op 112 B/op 2 allocs/op +BenchmarkTango_ParamWrite 3855218 308.3 ns/op 280 B/op 7 allocs/op +BenchmarkTigerTonic_ParamWrite 1000000 1090 ns/op 1024 B/op 18 allocs/op +BenchmarkTraffic_ParamWrite 742009 1523 ns/op 2248 B/op 25 allocs/op +BenchmarkVulcan_ParamWrite 6929622 170.7 ns/op 98 B/op 3 allocs/op +``` + +--- + +## Full Benchmark Results + +### GitHub API + +#### Static + +``` +BenchmarkGin_GithubStatic 43895277 28.10 ns/op 0 B/op 0 allocs/op +BenchmarkAce_GithubStatic 42779731 28.31 ns/op 0 B/op 0 allocs/op +BenchmarkAero_GithubStatic 83284414 14.50 ns/op 0 B/op 0 allocs/op +BenchmarkBear_GithubStatic 9311720 131.2 ns/op 120 B/op 3 allocs/op +BenchmarkBeego_GithubStatic 2897301 395.7 ns/op 352 B/op 3 allocs/op +BenchmarkBone_GithubStatic 308800 3903 ns/op 2880 B/op 60 allocs/op +BenchmarkChi_GithubStatic 5401872 229.6 ns/op 368 B/op 2 allocs/op +BenchmarkDenco_GithubStatic 98722773 11.71 ns/op 0 B/op 0 allocs/op +BenchmarkEcho_GithubStatic 40625690 27.23 ns/op 0 B/op 0 allocs/op +BenchmarkGocraftWeb_GithubStatic 5341020 229.8 ns/op 288 B/op 5 allocs/op +BenchmarkGoji_GithubStatic 15548287 76.12 ns/op 0 B/op 0 allocs/op +BenchmarkGojiv2_GithubStatic 2520218 490.3 ns/op 1120 B/op 7 allocs/op +BenchmarkGoJsonRest_GithubStatic 3861292 321.3 ns/op 297 B/op 11 allocs/op +BenchmarkGoRestful_GithubStatic 330211 3671 ns/op 4792 B/op 14 allocs/op +BenchmarkGorillaMux_GithubStatic 938425 1474 ns/op 848 B/op 7 allocs/op +BenchmarkGowwwRouter_GithubStatic 38324576 32.24 ns/op 0 B/op 0 allocs/op +BenchmarkHttpRouter_GithubStatic 69731800 17.26 ns/op 0 B/op 0 allocs/op +BenchmarkHttpTreeMux_GithubStatic 55391751 22.97 ns/op 0 B/op 0 allocs/op +BenchmarkKocha_GithubStatic 52384971 24.34 ns/op 0 B/op 0 allocs/op +BenchmarkLARS_GithubStatic 45034478 25.48 ns/op 0 B/op 0 allocs/op +BenchmarkMacaron_GithubStatic 2014342 578.0 ns/op 728 B/op 8 allocs/op +BenchmarkMartini_GithubStatic 554347 2686 ns/op 792 B/op 11 allocs/op +BenchmarkPat_GithubStatic 288867 4049 ns/op 3648 B/op 76 allocs/op +BenchmarkPossum_GithubStatic 3928141 306.4 ns/op 416 B/op 3 allocs/op +BenchmarkR2router_GithubStatic 11773146 97.06 ns/op 112 B/op 3 allocs/op +BenchmarkRivet_GithubStatic 37206849 32.03 ns/op 0 B/op 0 allocs/op +BenchmarkTango_GithubStatic 3806214 321.1 ns/op 192 B/op 6 allocs/op +BenchmarkTigerTonic_GithubStatic 15421950 82.96 ns/op 48 B/op 1 allocs/op +BenchmarkTraffic_GithubStatic 307382 3618 ns/op 4632 B/op 89 allocs/op +BenchmarkVulcan_GithubStatic 6107649 198.2 ns/op 98 B/op 3 allocs/op +``` + +#### Param + +``` +BenchmarkGin_GithubParam 25399108 50.29 ns/op 0 B/op 0 allocs/op +BenchmarkAce_GithubParam 12033406 102.1 ns/op 96 B/op 1 allocs/op +BenchmarkAero_GithubParam 34218457 35.12 ns/op 0 B/op 0 allocs/op +BenchmarkBear_GithubParam 3491167 340.3 ns/op 496 B/op 5 allocs/op +BenchmarkBeego_GithubParam 2462625 492.9 ns/op 352 B/op 3 allocs/op +BenchmarkBone_GithubParam 479170 2435 ns/op 1824 B/op 18 allocs/op +BenchmarkChi_GithubParam 2392147 439.7 ns/op 704 B/op 4 allocs/op +BenchmarkDenco_GithubParam 10566573 108.5 ns/op 128 B/op 1 allocs/op +BenchmarkEcho_GithubParam 22438311 53.46 ns/op 0 B/op 0 allocs/op +BenchmarkGocraftWeb_GithubParam 2686350 425.8 ns/op 656 B/op 7 allocs/op +BenchmarkGoji_GithubParam 3468987 331.6 ns/op 336 B/op 2 allocs/op +BenchmarkGojiv2_GithubParam 1713819 693.3 ns/op 1216 B/op 10 allocs/op +BenchmarkGoJsonRest_GithubParam 2105818 561.9 ns/op 681 B/op 14 allocs/op +BenchmarkGoRestful_GithubParam 268806 4732 ns/op 4696 B/op 15 allocs/op +BenchmarkGorillaMux_GithubParam 484622 2436 ns/op 1168 B/op 8 allocs/op +BenchmarkGowwwRouter_GithubParam 6445003 195.4 ns/op 368 B/op 2 allocs/op +BenchmarkHttpRouter_GithubParam 14665429 88.59 ns/op 96 B/op 1 allocs/op +BenchmarkHttpTreeMux_GithubParam 4199426 311.2 ns/op 384 B/op 4 allocs/op +BenchmarkKocha_GithubParam 8478230 139.3 ns/op 112 B/op 3 allocs/op +BenchmarkLARS_GithubParam 27976429 43.36 ns/op 0 B/op 0 allocs/op +BenchmarkMacaron_GithubParam 1475805 805.7 ns/op 1064 B/op 10 allocs/op +BenchmarkMartini_GithubParam 354076 3459 ns/op 1176 B/op 13 allocs/op +BenchmarkPat_GithubParam 422454 2919 ns/op 2360 B/op 45 allocs/op +BenchmarkPossum_GithubParam 3345200 349.5 ns/op 496 B/op 5 allocs/op +BenchmarkR2router_GithubParam 5887364 205.1 ns/op 400 B/op 4 allocs/op +BenchmarkRivet_GithubParam 9056540 118.9 ns/op 96 B/op 1 allocs/op +BenchmarkTango_GithubParam 3217730 376.9 ns/op 296 B/op 6 allocs/op +BenchmarkTigerTonic_GithubParam 1000000 1043 ns/op 1072 B/op 21 allocs/op +BenchmarkTraffic_GithubParam 375636 3171 ns/op 2840 B/op 43 allocs/op +BenchmarkVulcan_GithubParam 3770610 321.0 ns/op 98 B/op 3 allocs/op +``` + +#### All Routes + +``` +BenchmarkGin_GithubAll 135811 9058 ns/op 0 B/op 0 allocs/op +BenchmarkAce_GithubAll 61230 21354 ns/op 13792 B/op 167 allocs/op +BenchmarkAero_GithubAll 176716 6646 ns/op 0 B/op 0 allocs/op +BenchmarkBear_GithubAll 16941 69598 ns/op 86448 B/op 943 allocs/op +BenchmarkBeego_GithubAll 12163 97593 ns/op 71456 B/op 609 allocs/op +BenchmarkBone_GithubAll 1176 1040342 ns/op 709472 B/op 8453 allocs/op +BenchmarkChi_GithubAll 12346 98943 ns/op 130816 B/op 740 allocs/op +BenchmarkDenco_GithubAll 59050 22401 ns/op 20224 B/op 167 allocs/op +BenchmarkEcho_GithubAll 104632 12030 ns/op 0 B/op 0 allocs/op +BenchmarkGocraftWeb_GithubAll 13927 85845 ns/op 123552 B/op 1400 allocs/op +BenchmarkGoji_GithubAll 8512 158755 ns/op 56112 B/op 334 allocs/op +BenchmarkGojiv2_GithubAll 5108 226986 ns/op 313744 B/op 3712 allocs/op +BenchmarkGoJsonRest_GithubAll 9859 120437 ns/op 127875 B/op 2737 allocs/op +BenchmarkGoRestful_GithubAll 1359 863892 ns/op 1006744 B/op 3009 allocs/op +BenchmarkGorillaMux_GithubAll 974 1282012 ns/op 225666 B/op 1588 allocs/op +BenchmarkGowwwRouter_GithubAll 32976 35511 ns/op 61456 B/op 334 allocs/op +BenchmarkHttpRouter_GithubAll 89264 13840 ns/op 13792 B/op 167 allocs/op +BenchmarkHttpTreeMux_GithubAll 25005 49430 ns/op 65856 B/op 671 allocs/op +BenchmarkKocha_GithubAll 38254 33213 ns/op 20592 B/op 504 allocs/op +BenchmarkLARS_GithubAll 144225 8714 ns/op 0 B/op 0 allocs/op +BenchmarkMacaron_GithubAll 8706 131574 ns/op 147784 B/op 1624 allocs/op +BenchmarkMartini_GithubAll 825 1483537 ns/op 231418 B/op 2731 allocs/op +BenchmarkPat_GithubAll 838 1432291 ns/op 1421792 B/op 23019 allocs/op +BenchmarkPossum_GithubAll 18913 62291 ns/op 84448 B/op 609 allocs/op +BenchmarkR2router_GithubAll 26276 45938 ns/op 70832 B/op 776 allocs/op +BenchmarkRivet_GithubAll 49792 23337 ns/op 16272 B/op 167 allocs/op +BenchmarkTango_GithubAll 14306 84094 ns/op 53850 B/op 1215 allocs/op +BenchmarkTigerTonic_GithubAll 5797 209921 ns/op 188584 B/op 4300 allocs/op +BenchmarkTraffic_GithubAll 1044 1213864 ns/op 829175 B/op 14582 allocs/op +BenchmarkVulcan_GithubAll 19022 60788 ns/op 19894 B/op 609 allocs/op +``` + +### Google+ API + +#### Static + +``` +BenchmarkGin_GPlusStatic 50430675 22.47 ns/op 0 B/op 0 allocs/op +BenchmarkAce_GPlusStatic 51961077 23.43 ns/op 0 B/op 0 allocs/op +BenchmarkAero_GPlusStatic 86196060 13.97 ns/op 0 B/op 0 allocs/op +BenchmarkBear_GPlusStatic 11848935 99.99 ns/op 104 B/op 3 allocs/op +BenchmarkBeego_GPlusStatic 3394909 360.2 ns/op 352 B/op 3 allocs/op +BenchmarkBone_GPlusStatic 21614740 54.72 ns/op 32 B/op 1 allocs/op +BenchmarkChi_GPlusStatic 5905422 202.2 ns/op 368 B/op 2 allocs/op +BenchmarkDenco_GPlusStatic 100000000 11.25 ns/op 0 B/op 0 allocs/op +BenchmarkEcho_GPlusStatic 63868430 18.64 ns/op 0 B/op 0 allocs/op +BenchmarkGocraftWeb_GPlusStatic 6419139 183.5 ns/op 272 B/op 5 allocs/op +BenchmarkGoji_GPlusStatic 26074863 46.67 ns/op 0 B/op 0 allocs/op +BenchmarkGojiv2_GPlusStatic 2529218 474.7 ns/op 1120 B/op 7 allocs/op +BenchmarkGoJsonRest_GPlusStatic 4662106 254.6 ns/op 297 B/op 11 allocs/op +BenchmarkGoRestful_GPlusStatic 782607 1489 ns/op 4272 B/op 14 allocs/op +BenchmarkGorillaMux_GPlusStatic 2741367 417.2 ns/op 848 B/op 7 allocs/op +BenchmarkGowwwRouter_GPlusStatic 100000000 11.61 ns/op 0 B/op 0 allocs/op +BenchmarkHttpRouter_GPlusStatic 123925137 9.716 ns/op 0 B/op 0 allocs/op +BenchmarkHttpTreeMux_GPlusStatic 84271881 14.55 ns/op 0 B/op 0 allocs/op +BenchmarkKocha_GPlusStatic 96201384 12.78 ns/op 0 B/op 0 allocs/op +BenchmarkLARS_GPlusStatic 60936904 19.79 ns/op 0 B/op 0 allocs/op +BenchmarkMacaron_GPlusStatic 2281216 523.1 ns/op 728 B/op 8 allocs/op +BenchmarkMartini_GPlusStatic 1000000 1158 ns/op 792 B/op 11 allocs/op +BenchmarkPat_GPlusStatic 12473952 94.32 ns/op 96 B/op 2 allocs/op +BenchmarkPossum_GPlusStatic 4341033 283.0 ns/op 416 B/op 3 allocs/op +BenchmarkR2router_GPlusStatic 14272594 80.44 ns/op 112 B/op 3 allocs/op +BenchmarkRivet_GPlusStatic 64791607 18.26 ns/op 0 B/op 0 allocs/op +BenchmarkTango_GPlusStatic 5208178 231.0 ns/op 152 B/op 6 allocs/op +BenchmarkTigerTonic_GPlusStatic 26052549 45.54 ns/op 32 B/op 1 allocs/op +BenchmarkTraffic_GPlusStatic 1655068 664.6 ns/op 1080 B/op 15 allocs/op +BenchmarkVulcan_GPlusStatic 10144974 117.5 ns/op 98 B/op 3 allocs/op +``` + +#### Param + +``` +BenchmarkGin_GPlusParam 38126504 31.22 ns/op 0 B/op 0 allocs/op +BenchmarkAce_GPlusParam 15315734 70.21 ns/op 64 B/op 1 allocs/op +BenchmarkAero_GPlusParam 55314088 22.34 ns/op 0 B/op 0 allocs/op +BenchmarkBear_GPlusParam 3841524 285.5 ns/op 472 B/op 5 allocs/op +BenchmarkBeego_GPlusParam 2792283 414.8 ns/op 352 B/op 3 allocs/op +BenchmarkBone_GPlusParam 2710533 440.2 ns/op 752 B/op 5 allocs/op +BenchmarkChi_GPlusParam 3291210 369.3 ns/op 704 B/op 4 allocs/op +BenchmarkDenco_GPlusParam 19789339 64.83 ns/op 64 B/op 1 allocs/op +BenchmarkEcho_GPlusParam 40679114 30.04 ns/op 0 B/op 0 allocs/op +BenchmarkGocraftWeb_GPlusParam 3499014 343.7 ns/op 624 B/op 7 allocs/op +BenchmarkGoji_GPlusParam 5488542 232.6 ns/op 336 B/op 2 allocs/op +BenchmarkGojiv2_GPlusParam 2221576 543.0 ns/op 1136 B/op 8 allocs/op +BenchmarkGoJsonRest_GPlusParam 2624800 447.0 ns/op 617 B/op 13 allocs/op +BenchmarkGoRestful_GPlusParam 728508 1712 ns/op 4616 B/op 15 allocs/op +BenchmarkGorillaMux_GPlusParam 1370820 887.2 ns/op 1152 B/op 8 allocs/op +BenchmarkGowwwRouter_GPlusParam 7895398 147.6 ns/op 368 B/op 2 allocs/op +BenchmarkHttpRouter_GPlusParam 25334516 48.01 ns/op 64 B/op 1 allocs/op +BenchmarkHttpTreeMux_GPlusParam 5918101 198.7 ns/op 352 B/op 3 allocs/op +BenchmarkKocha_GPlusParam 15647581 77.64 ns/op 48 B/op 2 allocs/op +BenchmarkLARS_GPlusParam 41545491 28.48 ns/op 0 B/op 0 allocs/op +BenchmarkMacaron_GPlusParam 1619770 742.6 ns/op 1064 B/op 10 allocs/op +BenchmarkMartini_GPlusParam 927007 1412 ns/op 1096 B/op 12 allocs/op +BenchmarkPat_GPlusParam 2187026 545.2 ns/op 600 B/op 12 allocs/op +BenchmarkPossum_GPlusParam 3570588 341.9 ns/op 496 B/op 5 allocs/op +BenchmarkR2router_GPlusParam 6142230 195.6 ns/op 400 B/op 4 allocs/op +BenchmarkRivet_GPlusParam 21743265 56.36 ns/op 48 B/op 1 allocs/op +BenchmarkTango_GPlusParam 4237848 285.6 ns/op 216 B/op 6 allocs/op +BenchmarkTigerTonic_GPlusParam 1625415 752.7 ns/op 824 B/op 16 allocs/op +BenchmarkTraffic_GPlusParam 852801 1389 ns/op 1904 B/op 23 allocs/op +BenchmarkVulcan_GPlusParam 7105036 167.8 ns/op 98 B/op 3 allocs/op +``` + +#### 2 Params + +``` +BenchmarkGin_GPlus2Params 30045693 39.13 ns/op 0 B/op 0 allocs/op +BenchmarkAce_GPlus2Params 15562932 79.43 ns/op 64 B/op 1 allocs/op +BenchmarkAero_GPlus2Params 33729063 34.87 ns/op 0 B/op 0 allocs/op +BenchmarkBear_GPlus2Params 3764409 318.7 ns/op 496 B/op 5 allocs/op +BenchmarkBeego_GPlus2Params 2423888 494.5 ns/op 352 B/op 3 allocs/op +BenchmarkBone_GPlus2Params 1000000 1090 ns/op 1104 B/op 9 allocs/op +BenchmarkChi_GPlus2Params 3077922 392.4 ns/op 704 B/op 4 allocs/op +BenchmarkDenco_GPlus2Params 14066016 85.80 ns/op 64 B/op 1 allocs/op +BenchmarkEcho_GPlus2Params 29279718 41.98 ns/op 0 B/op 0 allocs/op +BenchmarkGocraftWeb_GPlus2Params 3111852 369.1 ns/op 656 B/op 7 allocs/op +BenchmarkGoji_GPlus2Params 3919934 298.6 ns/op 336 B/op 2 allocs/op +BenchmarkGojiv2_GPlus2Params 1724162 698.0 ns/op 1216 B/op 11 allocs/op +BenchmarkGoJsonRest_GPlus2Params 2149428 557.3 ns/op 681 B/op 14 allocs/op +BenchmarkGoRestful_GPlus2Params 573634 1893 ns/op 4712 B/op 15 allocs/op +BenchmarkGorillaMux_GPlus2Params 682111 1824 ns/op 1168 B/op 8 allocs/op +BenchmarkGowwwRouter_GPlus2Params 7580608 156.0 ns/op 368 B/op 2 allocs/op +BenchmarkHttpRouter_GPlus2Params 20394765 59.07 ns/op 64 B/op 1 allocs/op +BenchmarkHttpTreeMux_GPlus2Params 5053549 238.5 ns/op 384 B/op 4 allocs/op +BenchmarkKocha_GPlus2Params 8661169 137.7 ns/op 112 B/op 3 allocs/op +BenchmarkLARS_GPlus2Params 32620809 37.02 ns/op 0 B/op 0 allocs/op +BenchmarkMacaron_GPlus2Params 1484382 828.6 ns/op 1064 B/op 10 allocs/op +BenchmarkMartini_GPlus2Params 375764 3118 ns/op 1224 B/op 15 allocs/op +BenchmarkPat_GPlus2Params 593236 1964 ns/op 2136 B/op 31 allocs/op +BenchmarkPossum_GPlus2Params 3535449 338.7 ns/op 496 B/op 5 allocs/op +BenchmarkR2router_GPlus2Params 6382530 189.1 ns/op 400 B/op 4 allocs/op +BenchmarkRivet_GPlus2Params 13734822 86.79 ns/op 96 B/op 1 allocs/op +BenchmarkTango_GPlus2Params 3824863 306.1 ns/op 296 B/op 6 allocs/op +BenchmarkTigerTonic_GPlus2Params 1000000 1078 ns/op 1152 B/op 21 allocs/op +BenchmarkTraffic_GPlus2Params 468492 2531 ns/op 2296 B/op 31 allocs/op +BenchmarkVulcan_GPlus2Params 4796979 248.9 ns/op 98 B/op 3 allocs/op +``` + +#### All Routes + +``` +BenchmarkGin_GPlusAll 2893287 412.3 ns/op 0 B/op 0 allocs/op +BenchmarkAce_GPlusAll 1329721 912.1 ns/op 640 B/op 11 allocs/op +BenchmarkAero_GPlusAll 3728048 323.2 ns/op 0 B/op 0 allocs/op +BenchmarkBear_GPlusAll 310212 3637 ns/op 5488 B/op 61 allocs/op +BenchmarkBeego_GPlusAll 215176 5681 ns/op 4576 B/op 39 allocs/op +BenchmarkBone_GPlusAll 117496 10217 ns/op 11040 B/op 98 allocs/op +BenchmarkChi_GPlusAll 238798 4876 ns/op 8480 B/op 48 allocs/op +BenchmarkDenco_GPlusAll 1313409 910.9 ns/op 672 B/op 11 allocs/op +BenchmarkEcho_GPlusAll 2705866 426.0 ns/op 0 B/op 0 allocs/op +BenchmarkGocraftWeb_GPlusAll 263034 4459 ns/op 7600 B/op 87 allocs/op +BenchmarkGoji_GPlusAll 399655 2891 ns/op 3696 B/op 22 allocs/op +BenchmarkGojiv2_GPlusAll 154381 7584 ns/op 15120 B/op 115 allocs/op +BenchmarkGoJsonRest_GPlusAll 181494 6304 ns/op 7701 B/op 170 allocs/op +BenchmarkGoRestful_GPlusAll 52003 23142 ns/op 60720 B/op 193 allocs/op +BenchmarkGorillaMux_GPlusAll 87273 13911 ns/op 14448 B/op 102 allocs/op +BenchmarkGowwwRouter_GPlusAll 574188 1858 ns/op 4048 B/op 22 allocs/op +BenchmarkHttpRouter_GPlusAll 1877773 649.1 ns/op 640 B/op 11 allocs/op +BenchmarkHttpTreeMux_GPlusAll 473188 2373 ns/op 4032 B/op 38 allocs/op +BenchmarkKocha_GPlusAll 1000000 1323 ns/op 848 B/op 27 allocs/op +BenchmarkLARS_GPlusAll 3073754 382.6 ns/op 0 B/op 0 allocs/op +BenchmarkMacaron_GPlusAll 178746 6983 ns/op 9464 B/op 104 allocs/op +BenchmarkMartini_GPlusAll 48831 24600 ns/op 14328 B/op 171 allocs/op +BenchmarkPat_GPlusAll 76422 15692 ns/op 15272 B/op 269 allocs/op +BenchmarkPossum_GPlusAll 316477 3773 ns/op 5408 B/op 39 allocs/op +BenchmarkR2router_GPlusAll 520474 2423 ns/op 4624 B/op 50 allocs/op +BenchmarkRivet_GPlusAll 1295100 928.1 ns/op 768 B/op 11 allocs/op +BenchmarkTango_GPlusAll 298516 3843 ns/op 3008 B/op 78 allocs/op +BenchmarkTigerTonic_GPlusAll 101194 11505 ns/op 11160 B/op 237 allocs/op +BenchmarkTraffic_GPlusAll 53414 22350 ns/op 26616 B/op 366 allocs/op +BenchmarkVulcan_GPlusAll 463639 2531 ns/op 1274 B/op 39 allocs/op +``` + +### Parse API + +#### Static + +``` +BenchmarkGin_ParseStatic 53518070 22.62 ns/op 0 B/op 0 allocs/op +BenchmarkAce_ParseStatic 52354974 23.33 ns/op 0 B/op 0 allocs/op +BenchmarkAero_ParseStatic 87150981 13.87 ns/op 0 B/op 0 allocs/op +BenchmarkBear_ParseStatic 9958563 121.5 ns/op 120 B/op 3 allocs/op +BenchmarkBeego_ParseStatic 3357967 355.5 ns/op 352 B/op 3 allocs/op +BenchmarkBone_ParseStatic 6466970 185.2 ns/op 144 B/op 3 allocs/op +BenchmarkChi_ParseStatic 5862630 198.8 ns/op 368 B/op 2 allocs/op +BenchmarkDenco_ParseStatic 100000000 12.05 ns/op 0 B/op 0 allocs/op +BenchmarkEcho_ParseStatic 62838466 18.40 ns/op 0 B/op 0 allocs/op +BenchmarkGocraftWeb_ParseStatic 6035592 197.0 ns/op 288 B/op 5 allocs/op +BenchmarkGoji_ParseStatic 18933330 63.23 ns/op 0 B/op 0 allocs/op +BenchmarkGojiv2_ParseStatic 2645055 447.3 ns/op 1120 B/op 7 allocs/op +BenchmarkGoJsonRest_ParseStatic 4464429 271.8 ns/op 297 B/op 11 allocs/op +BenchmarkGoRestful_ParseStatic 653388 1786 ns/op 4792 B/op 14 allocs/op +BenchmarkGorillaMux_ParseStatic 2294398 508.1 ns/op 848 B/op 7 allocs/op +BenchmarkGowwwRouter_ParseStatic 85855849 13.51 ns/op 0 B/op 0 allocs/op +BenchmarkHttpRouter_ParseStatic 100000000 10.71 ns/op 0 B/op 0 allocs/op +BenchmarkHttpTreeMux_ParseStatic 60829818 20.59 ns/op 0 B/op 0 allocs/op +BenchmarkKocha_ParseStatic 86461821 13.88 ns/op 0 B/op 0 allocs/op +BenchmarkLARS_ParseStatic 60537139 19.89 ns/op 0 B/op 0 allocs/op +BenchmarkMacaron_ParseStatic 2327062 511.8 ns/op 728 B/op 8 allocs/op +BenchmarkMartini_ParseStatic 1000000 1223 ns/op 792 B/op 11 allocs/op +BenchmarkPat_ParseStatic 5077684 234.6 ns/op 240 B/op 5 allocs/op +BenchmarkPossum_ParseStatic 4378826 276.9 ns/op 416 B/op 3 allocs/op +BenchmarkR2router_ParseStatic 13918509 86.61 ns/op 112 B/op 3 allocs/op +BenchmarkRivet_ParseStatic 59392341 19.74 ns/op 0 B/op 0 allocs/op +BenchmarkTango_ParseStatic 4877336 253.6 ns/op 192 B/op 6 allocs/op +BenchmarkTigerTonic_ParseStatic 17529486 68.49 ns/op 48 B/op 1 allocs/op +BenchmarkTraffic_ParseStatic 1513068 781.4 ns/op 1224 B/op 18 allocs/op +BenchmarkVulcan_ParseStatic 8955946 134.6 ns/op 98 B/op 3 allocs/op +``` + +#### Param + +``` +BenchmarkGin_ParseParam 46613631 25.30 ns/op 0 B/op 0 allocs/op +BenchmarkAce_ParseParam 19263414 62.50 ns/op 64 B/op 1 allocs/op +BenchmarkAero_ParseParam 65469127 18.25 ns/op 0 B/op 0 allocs/op +BenchmarkBear_ParseParam 4148041 282.4 ns/op 467 B/op 5 allocs/op +BenchmarkBeego_ParseParam 3173386 382.8 ns/op 352 B/op 3 allocs/op +BenchmarkBone_ParseParam 2519083 472.7 ns/op 832 B/op 6 allocs/op +BenchmarkChi_ParseParam 3320446 368.9 ns/op 704 B/op 4 allocs/op +BenchmarkDenco_ParseParam 20528611 56.96 ns/op 64 B/op 1 allocs/op +BenchmarkEcho_ParseParam 53122124 22.99 ns/op 0 B/op 0 allocs/op +BenchmarkGocraftWeb_ParseParam 3454389 346.5 ns/op 640 B/op 7 allocs/op +BenchmarkGoji_ParseParam 5256088 235.8 ns/op 336 B/op 2 allocs/op +BenchmarkGojiv2_ParseParam 2296279 519.1 ns/op 1168 B/op 9 allocs/op +BenchmarkGoJsonRest_ParseParam 2735005 433.4 ns/op 617 B/op 13 allocs/op +BenchmarkGoRestful_ParseParam 559504 1927 ns/op 5112 B/op 15 allocs/op +BenchmarkGorillaMux_ParseParam 1812528 634.8 ns/op 1152 B/op 8 allocs/op +BenchmarkGowwwRouter_ParseParam 8530036 142.9 ns/op 368 B/op 2 allocs/op +BenchmarkHttpRouter_ParseParam 29872574 40.20 ns/op 64 B/op 1 allocs/op +BenchmarkHttpTreeMux_ParseParam 6568846 185.7 ns/op 352 B/op 3 allocs/op +BenchmarkKocha_ParseParam 16294209 71.62 ns/op 48 B/op 2 allocs/op +BenchmarkLARS_ParseParam 56620798 21.32 ns/op 0 B/op 0 allocs/op +BenchmarkMacaron_ParseParam 1664428 732.1 ns/op 1064 B/op 10 allocs/op +BenchmarkMartini_ParseParam 981326 1318 ns/op 1096 B/op 12 allocs/op +BenchmarkPat_ParseParam 1675594 712.1 ns/op 992 B/op 15 allocs/op +BenchmarkPossum_ParseParam 3543426 336.8 ns/op 496 B/op 5 allocs/op +BenchmarkR2router_ParseParam 6078027 198.4 ns/op 400 B/op 4 allocs/op +BenchmarkRivet_ParseParam 23278633 52.40 ns/op 48 B/op 1 allocs/op +BenchmarkTango_ParseParam 4534116 268.0 ns/op 224 B/op 6 allocs/op +BenchmarkTigerTonic_ParseParam 1706557 715.8 ns/op 752 B/op 15 allocs/op +BenchmarkTraffic_ParseParam 963790 1191 ns/op 1928 B/op 23 allocs/op +BenchmarkVulcan_ParseParam 8465382 139.8 ns/op 98 B/op 3 allocs/op +``` + +#### 2 Params + +``` +BenchmarkGin_Parse2Params 39753472 30.02 ns/op 0 B/op 0 allocs/op +BenchmarkAce_Parse2Params 18333952 68.63 ns/op 64 B/op 1 allocs/op +BenchmarkAero_Parse2Params 52058101 22.95 ns/op 0 B/op 0 allocs/op +BenchmarkBear_Parse2Params 3673090 321.8 ns/op 496 B/op 5 allocs/op +BenchmarkBeego_Parse2Params 2765089 431.9 ns/op 352 B/op 3 allocs/op +BenchmarkBone_Parse2Params 2676722 458.0 ns/op 784 B/op 5 allocs/op +BenchmarkChi_Parse2Params 3197473 378.5 ns/op 704 B/op 4 allocs/op +BenchmarkDenco_Parse2Params 17205883 68.76 ns/op 64 B/op 1 allocs/op +BenchmarkEcho_Parse2Params 43142511 28.68 ns/op 0 B/op 0 allocs/op +BenchmarkGocraftWeb_Parse2Params 3212872 372.8 ns/op 656 B/op 7 allocs/op +BenchmarkGoji_Parse2Params 5678137 208.5 ns/op 336 B/op 2 allocs/op +BenchmarkGojiv2_Parse2Params 2286504 527.8 ns/op 1152 B/op 8 allocs/op +BenchmarkGoJsonRest_Parse2Params 2387936 501.1 ns/op 681 B/op 14 allocs/op +BenchmarkGoRestful_Parse2Params 507566 2179 ns/op 5536 B/op 15 allocs/op +BenchmarkGorillaMux_Parse2Params 1516276 791.5 ns/op 1168 B/op 8 allocs/op +BenchmarkGowwwRouter_Parse2Params 7861905 149.0 ns/op 368 B/op 2 allocs/op +BenchmarkHttpRouter_Parse2Params 25059865 47.14 ns/op 64 B/op 1 allocs/op +BenchmarkHttpTreeMux_Parse2Params 5467455 218.1 ns/op 384 B/op 4 allocs/op +BenchmarkKocha_Parse2Params 10478869 114.7 ns/op 112 B/op 3 allocs/op +BenchmarkLARS_Parse2Params 44204389 26.18 ns/op 0 B/op 0 allocs/op +BenchmarkMacaron_Parse2Params 1570063 758.0 ns/op 1064 B/op 10 allocs/op +BenchmarkMartini_Parse2Params 885129 1407 ns/op 1176 B/op 13 allocs/op +BenchmarkPat_Parse2Params 1701120 706.4 ns/op 768 B/op 17 allocs/op +BenchmarkPossum_Parse2Params 3545026 341.2 ns/op 496 B/op 5 allocs/op +BenchmarkR2router_Parse2Params 6219794 199.8 ns/op 400 B/op 4 allocs/op +BenchmarkRivet_Parse2Params 15446226 77.50 ns/op 96 B/op 1 allocs/op +BenchmarkTango_Parse2Params 4123059 285.0 ns/op 264 B/op 6 allocs/op +BenchmarkTigerTonic_Parse2Params 1000000 1053 ns/op 1120 B/op 21 allocs/op +BenchmarkTraffic_Parse2Params 870003 1372 ns/op 1992 B/op 25 allocs/op +BenchmarkVulcan_Parse2Params 7048611 168.3 ns/op 98 B/op 3 allocs/op +``` + +#### All Routes + +``` +BenchmarkGin_ParseAll 1681276 719.8 ns/op 0 B/op 0 allocs/op +BenchmarkAce_ParseAll 1000000 1445 ns/op 640 B/op 16 allocs/op +BenchmarkAero_ParseAll 2210972 546.0 ns/op 0 B/op 0 allocs/op +BenchmarkBear_ParseAll 179937 6452 ns/op 8920 B/op 110 allocs/op +BenchmarkBeego_ParseAll 114976 10182 ns/op 9152 B/op 78 allocs/op +BenchmarkBone_ParseAll 99656 11868 ns/op 15184 B/op 131 allocs/op +BenchmarkChi_ParseAll 137953 8453 ns/op 14944 B/op 84 allocs/op +BenchmarkDenco_ParseAll 1000000 1291 ns/op 928 B/op 16 allocs/op +BenchmarkEcho_ParseAll 1656105 723.0 ns/op 0 B/op 0 allocs/op +BenchmarkGocraftWeb_ParseAll 142503 8165 ns/op 13168 B/op 162 allocs/op +BenchmarkGoji_ParseAll 240613 4792 ns/op 5376 B/op 32 allocs/op +BenchmarkGojiv2_ParseAll 85312 13700 ns/op 29456 B/op 199 allocs/op +BenchmarkGoJsonRest_ParseAll 105716 11300 ns/op 13034 B/op 321 allocs/op +BenchmarkGoRestful_ParseAll 22760 52633 ns/op 131728 B/op 380 allocs/op +BenchmarkGorillaMux_ParseAll 46082 26107 ns/op 26960 B/op 198 allocs/op +BenchmarkGowwwRouter_ParseAll 363032 2924 ns/op 5888 B/op 32 allocs/op +BenchmarkHttpRouter_ParseAll 1292341 921.5 ns/op 640 B/op 16 allocs/op +BenchmarkHttpTreeMux_ParseAll 322304 3484 ns/op 5728 B/op 51 allocs/op +BenchmarkKocha_ParseAll 834361 1813 ns/op 960 B/op 35 allocs/op +BenchmarkLARS_ParseAll 1779954 669.4 ns/op 0 B/op 0 allocs/op +BenchmarkMacaron_ParseAll 87348 13595 ns/op 18928 B/op 208 allocs/op +BenchmarkMartini_ParseAll 30399 39785 ns/op 25696 B/op 305 allocs/op +BenchmarkPat_ParseAll 70246 17221 ns/op 15376 B/op 323 allocs/op +BenchmarkPossum_ParseAll 159716 7413 ns/op 10816 B/op 78 allocs/op +BenchmarkR2router_ParseAll 258717 4338 ns/op 7520 B/op 94 allocs/op +BenchmarkRivet_ParseAll 1000000 1385 ns/op 912 B/op 16 allocs/op +BenchmarkTango_ParseAll 157684 7464 ns/op 5864 B/op 156 allocs/op +BenchmarkTigerTonic_ParseAll 76174 16031 ns/op 15488 B/op 329 allocs/op +BenchmarkTraffic_ParseAll 34507 34164 ns/op 45760 B/op 630 allocs/op +BenchmarkVulcan_ParseAll 253556 5019 ns/op 2548 B/op 78 allocs/op +``` + +### Static Routes + +``` +BenchmarkGin_StaticAll 214844 5566 ns/op 0 B/op 0 allocs/op +BenchmarkHttpServeMux_StaticAll 63081 18896 ns/op 0 B/op 0 allocs/op +BenchmarkAce_StaticAll 199526 5981 ns/op 0 B/op 0 allocs/op +BenchmarkAero_StaticAll 420883 2872 ns/op 0 B/op 0 allocs/op +BenchmarkBear_StaticAll 54873 22053 ns/op 19960 B/op 469 allocs/op +BenchmarkBeego_StaticAll 17143 69371 ns/op 55264 B/op 471 allocs/op +BenchmarkBone_StaticAll 50510 23765 ns/op 0 B/op 0 allocs/op +BenchmarkChi_StaticAll 29125 41246 ns/op 57776 B/op 314 allocs/op +BenchmarkDenco_StaticAll 528363 2240 ns/op 0 B/op 0 allocs/op +BenchmarkEcho_StaticAll 167440 6714 ns/op 0 B/op 0 allocs/op +BenchmarkGocraftWeb_StaticAll 32882 36485 ns/op 45056 B/op 785 allocs/op +BenchmarkGoji_StaticAll 65331 18211 ns/op 0 B/op 0 allocs/op +BenchmarkGojiv2_StaticAll 13905 86141 ns/op 175840 B/op 1099 allocs/op +BenchmarkGoJsonRest_StaticAll 20342 59899 ns/op 46629 B/op 1727 allocs/op +BenchmarkGoRestful_StaticAll 2685 447104 ns/op 677824 B/op 2193 allocs/op +BenchmarkGorillaMux_StaticAll 3967 300555 ns/op 133137 B/op 1099 allocs/op +BenchmarkGowwwRouter_StaticAll 179246 6622 ns/op 0 B/op 0 allocs/op +BenchmarkHttpRouter_StaticAll 291186 4095 ns/op 0 B/op 0 allocs/op +BenchmarkHttpTreeMux_StaticAll 295596 4031 ns/op 0 B/op 0 allocs/op +BenchmarkKocha_StaticAll 198813 6013 ns/op 0 B/op 0 allocs/op +BenchmarkLARS_StaticAll 220419 5272 ns/op 0 B/op 0 allocs/op +BenchmarkMacaron_StaticAll 14395 82544 ns/op 114296 B/op 1256 allocs/op +BenchmarkMartini_StaticAll 2061 577268 ns/op 129209 B/op 2031 allocs/op +BenchmarkPat_StaticAll 1453 813157 ns/op 602832 B/op 12559 allocs/op +BenchmarkPossum_StaticAll 26097 45967 ns/op 65312 B/op 471 allocs/op +BenchmarkR2router_StaticAll 61281 19281 ns/op 17584 B/op 471 allocs/op +BenchmarkRivet_StaticAll 132847 9082 ns/op 0 B/op 0 allocs/op +BenchmarkTango_StaticAll 20103 59732 ns/op 31274 B/op 942 allocs/op +BenchmarkTigerTonic_StaticAll 83690 14425 ns/op 7376 B/op 157 allocs/op +BenchmarkTraffic_StaticAll 1669 699470 ns/op 749837 B/op 14444 allocs/op +BenchmarkVulcan_StaticAll 31063 38764 ns/op 15386 B/op 471 allocs/op ``` From a749e4d33c2db35835581c60604720614e570cd6 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sun, 15 Mar 2026 14:34:58 +0800 Subject: [PATCH 35/70] docs: replace AUTHORS.md with link to GitHub contributors page (#4582) AUTHORS.md was a manually maintained list of 400+ contributors that had no automation to keep it current. Replace it with a link to GitHub s built-in contributors page which is always up-to-date. Co-authored-by: Claude Opus 4.6 (1M context) --- AUTHORS.md | 406 ----------------------------------------------------- README.md | 2 +- 2 files changed, 1 insertion(+), 407 deletions(-) delete mode 100644 AUTHORS.md diff --git a/AUTHORS.md b/AUTHORS.md deleted file mode 100644 index b4773ef3..00000000 --- a/AUTHORS.md +++ /dev/null @@ -1,406 +0,0 @@ -List of all the awesome people working to make Gin the best Web Framework in Go. - -## gin 1.x series authors - -**Gin Core Team:** Bo-Yi Wu (@appleboy), thinkerou (@thinkerou), Javier Provecho (@javierprovecho) - -## gin 0.x series authors - -**Maintainers:** Manu Martinez-Almeida (@manucorporat), Javier Provecho (@javierprovecho) - ------- - -People and companies, who have contributed, in alphabetical order. - -- 178inaba <178inaba@users.noreply.github.com> -- A. F -- ABHISHEK SONI -- Abhishek Chanda -- Abner Chen -- AcoNCodes -- Adam Dratwinski -- Adam Mckaig -- Adam Zielinski -- Adonis -- Alan Wang -- Albin Gilles -- Aleksandr Didenko -- Alessandro (Ale) Segala <43508+ItalyPaleAle@users.noreply.github.com> -- Alex -- Alexander -- Alexander Lokhman -- Alexander Melentyev <55826637+alexander-melentyev@users.noreply.github.com> -- Alexander Nyquist -- Allen Ren -- AllinGo -- Ammar Bandukwala -- An Xiao (Luffy) -- Andre Dublin <81dublin@gmail.com> -- Andrew Szeto -- Andrey Abramov -- Andrey Nering -- Andrey Smirnov -- Andrii Bubis -- André Bazaglia -- Andy Pan -- Antoine GIRARD -- Anup Kumar Panwar <1anuppanwar@gmail.com> -- Aravinth Sundaram -- Artem -- Ashwani -- Aurelien Regat-Barrel -- Austin Heap -- Barnabus -- Bo-Yi Wu -- Boris Borshevsky -- Boyi Wu -- BradyBromley <51128276+BradyBromley@users.noreply.github.com> -- Brendan Fosberry -- Brian Wigginton -- Carlos Eduardo -- Chad Russell -- Charles -- Christian Muehlhaeuser -- Christian Persson -- Christopher Harrington -- Damon Zhao -- Dan Markham -- Dang Nguyen -- Daniel Krom -- Daniel M. Lambea -- Danieliu -- David Irvine -- David Zhang -- Davor Kapsa -- DeathKing -- Dennis Cho <47404603+forest747@users.noreply.github.com> -- Dmitry Dorogin -- Dmitry Kutakov -- Dmitry Sedykh -- Don2Quixote <35610661+Don2Quixote@users.noreply.github.com> -- Donn Pebe -- Dustin Decker -- Eason Lin -- Edward Betts -- Egor Seredin <4819888+agmt@users.noreply.github.com> -- Emmanuel Goh -- Equim -- Eren A. Akyol -- Eric_Lee -- Erik Bender -- Ethan Kan -- Evgeny Persienko -- Faisal Alam -- Fareed Dudhia -- Filip Figiel -- Florian Polster -- Frank Bille -- Franz Bettag -- Ganlv -- Gaozhen Ying -- George Gabolaev -- George Kirilenko -- Georges Varouchas -- Gordon Tyler -- Harindu Perera -- Helios <674876158@qq.com> -- Henry Kwan -- Henry Yee -- Himanshu Mishra -- Hiroyuki Tanaka -- Ibraheem Ahmed -- Ignacio Galindo -- Igor H. Vieira -- Ildar1111 <54001462+Ildar1111@users.noreply.github.com> -- Iskander (Alex) Sharipov -- Ismail Gjevori -- Ivan Chen -- JINNOUCHI Yasushi -- James Pettyjohn -- Jamie Stackhouse -- Jason Lee -- Javier Provecho -- Javier Provecho -- Javier Provecho -- Javier Provecho Fernandez -- Javier Provecho Fernandez -- Jean-Christophe Lebreton -- Jeff -- Jeremy Loy -- Jim Filippou -- Jimmy Pettersson -- John Bampton -- Johnny Dallas -- Johnny Dallas -- Jonathan (JC) Chen -- Josep Jesus Bigorra Algaba <42377845+averageflow@users.noreply.github.com> -- Josh Horowitz -- Joshua Loper -- Julien Schmidt -- Jun Kimura -- Justin Beckwith -- Justin Israel -- Justin Mayhew -- Jérôme Laforge -- Kacper Bąk <56700396+53jk1@users.noreply.github.com> -- Kamron Batman -- Kane Rogers -- Kaushik Neelichetty -- Keiji Yoshida -- Kel Cecil -- Kevin Mulvey -- Kevin Zhu -- Kirill Motkov -- Klemen Sever -- Kristoffer A. Iversen -- Krzysztof Szafrański -- Kumar McMillan -- Kyle Mcgill -- Lanco <35420416+lancoLiu@users.noreply.github.com> -- Levi Olson -- Lin Kao-Yuan -- Linus Unnebäck -- Lucas Clemente -- Ludwig Valda Vasquez -- Luis GG -- MW Lim -- Maksimov Sergey -- Manjusaka -- Manu MA -- Manu MA -- Manu Mtz-Almeida -- Manu Mtz.-Almeida -- Manuel Alonso -- Mara Kim -- Mario Kostelac -- Martin Karlsch -- Matt Newberry -- Matt Williams -- Matthieu MOREL -- Max Hilbrunner -- Maxime Soulé -- MetalBreaker -- Michael Puncel -- MichaelDeSteven <51652084+MichaelDeSteven@users.noreply.github.com> -- Mike <38686456+icy4ever@users.noreply.github.com> -- Mike Stipicevic -- Miki Tebeka -- Miles -- Mirza Ceric -- Mykyta Semenistyi -- Naoki Takano -- Ngalim Siregar -- Ni Hao -- Nick Gerakines -- Nikifor Seryakov -- Notealot <714804968@qq.com> -- Olivier Mengué -- Olivier Robardet -- Pablo Moncada -- Pablo Moncada -- Panmax <967168@qq.com> -- Peperoncino <2wua4nlyi@gmail.com> -- Philipp Meinen -- Pierre Massat -- Qt -- Quentin ROYER -- README Bot <35302948+codetriage-readme-bot@users.noreply.github.com> -- Rafal Zajac -- Rahul Datta Roy -- Rajiv Kilaparti -- Raphael Gavache -- Ray Rodriguez -- Regner Blok-Andersen -- Remco -- Rex Lee(李俊) -- Richard Lee -- Riverside -- Robert Wilkinson -- Rogier Lommers -- Rohan Pai -- Romain Beuque -- Roman Belyakovsky -- Roman Zaynetdinov <627197+zaynetro@users.noreply.github.com> -- Roman Zaynetdinov -- Ronald Petty -- Ross Wolf <31489089+rw-access@users.noreply.github.com> -- Roy Lou -- Rubi <14269809+codenoid@users.noreply.github.com> -- Ryan <46182144+ryanker@users.noreply.github.com> -- Ryan J. Yoder -- SRK.Lyu -- Sai -- Samuel Abreu -- Santhosh Kumar -- Sasha Melentyev -- Sasha Myasoedov -- Segev Finer -- Sergey Egorov -- Sergey Fedchenko -- Sergey Gonimar -- Sergey Ponomarev -- Serica <943914044@qq.com> -- Shamus Taylor -- Shilin Wang -- Shuo -- Skuli Oskarsson -- Snawoot -- Sridhar Ratnakumar -- Steeve Chailloux -- Sudhir Mishra -- Suhas Karanth -- TaeJun Park -- Tatsuya Hoshino -- Tevic -- Tevin Jeffrey -- The Gitter Badger -- Thibault Jamet -- Thomas Boerger -- Thomas Schaffer -- Tommy Chu -- Tudor Roman -- Uwe Dauernheim -- Valentine Oragbakosi -- Vas N -- Vasilyuk Vasiliy -- Victor Castell -- Vince Yuan -- Vyacheslav Dubinin -- Waynerv -- Weilin Shi <934587911@qq.com> -- Xudong Cai -- Yasuhiro Matsumoto -- Yehezkiel Syamsuhadi -- Yoshiki Nakagawa -- Yoshiyuki Kinjo -- Yue Yang -- ZYunH -- Zach Newburgh -- Zasda Yusuf Mikail -- ZhangYunHao -- ZhiFeng Hu -- Zhu Xi -- a2tt -- ahuigo <1781999+ahuigo@users.noreply.github.com> -- ali -- aljun -- andrea -- andriikushch -- anoty -- awkj -- axiaoxin <254606826@qq.com> -- bbiao -- bestgopher <84328409@qq.com> -- betahu -- bigwheel -- bn4t <17193640+bn4t@users.noreply.github.com> -- bullgare -- chainhelen -- chenyang929 -- chriswhelix -- collinmsn <4130944@qq.com> -- cssivision -- danielalves -- delphinus -- dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> -- dickeyxxx -- edebernis -- error10 -- esplo -- eudore <30709860+eudore@users.noreply.github.com> -- ffhelicopter <32922889+ffhelicopter@users.noreply.github.com> -- filikos <11477309+filikos@users.noreply.github.com> -- forging2012 -- goqihoo -- grapeVine -- guonaihong -- heige -- heige -- hellojukay -- henrylee2cn -- htobenothing -- iamhesir <78344375+iamhesir@users.noreply.github.com> -- ijaa -- ishanray -- ishanray -- itcloudy <272685110@qq.com> -- jarodsong6 -- jasonrhansen -- jincheng9 -- joeADSP <75027008+joeADSP@users.noreply.github.com> -- junfengye -- kaiiak -- kebo -- keke <19yamashita15@gmail.com> -- kishor kunal raj <68464660+kishorkunal-raj@users.noreply.github.com> -- kyledinh -- lantw44 -- likakuli <1154584512@qq.com> -- linfangrong -- linzi <873804682@qq.com> -- llgoer -- long-road <13412081338@163.com> -- mbesancon -- mehdy -- metal A-wing -- micanzhang -- minarc -- mllu -- mopemoepe -- msoedov -- mstmdev -- novaeye -- olebedev -- phithon -- pjgg -- qm012 <67568757+qm012@users.noreply.github.com> -- raymonder jin -- rns -- root@andrea:~# -- sekky0905 <20237968+sekky0905@users.noreply.github.com> -- senhtry -- shadrus -- silasb -- solos -- songjiayang -- sope -- srt180 <30768686+srt180@users.noreply.github.com> -- stackerzzq -- sunshineplan -- syssam -- techjanitor -- techjanitor -- thinkerou -- thinkgo <49174849+thinkgos@users.noreply.github.com> -- tsirolnik -- tyltr <31768692+tylitianrui@users.noreply.github.com> -- vinhha96 -- voidman -- vz -- wei -- weibaohui -- whirosan -- willnewrelic -- wssccc -- wuhuizuo -- xyb -- y-yagi -- yiranzai -- youzeliang -- yugu -- yuyabe -- zebozhuang -- zero11-0203 <93071220+zero11-0203@users.noreply.github.com> -- zesani <7sin@outlook.co.th> -- zhanweidu -- zhing -- ziheng -- zzjin -- 森 優太 <59682979+uta-mori@users.noreply.github.com> -- 杰哥 <858806258@qq.com> -- 涛叔 -- 市民233 -- 尹宝强 -- 梦溪笔谈 -- 飞雪无情 -- 寻寻觅觅的Gopher diff --git a/README.md b/README.md index d6492c06..96b0ae3c 100644 --- a/README.md +++ b/README.md @@ -209,7 +209,7 @@ Gin powers many high-traffic applications and services in production: ## 🤝 Contributing -Gin is the work of hundreds of contributors from around the world. We welcome and appreciate your contributions! +Gin is the work of hundreds of contributors from around the world. We welcome and appreciate your contributions! See the full list of [contributors](https://github.com/gin-gonic/gin/graphs/contributors). ### How to Contribute From ecd26c8835574b47acdc9cb6a5dddcc6fe922140 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sun, 15 Mar 2026 17:16:42 +0800 Subject: [PATCH 36/70] docs(readme): update benchmark results with latest data (#4583) - Remove 20 deprecated frameworks from benchmark report - Add BunRouter and Fiber as newly benchmarked routers - Add ranked summary table based on GitHub API throughput - Add memory consumption tables sorted by bytes ascending - Include all micro and API benchmark results with rankings Co-authored-by: Claude Opus 4.6 (1M context) --- BENCHMARKS.md | 993 ++++++++++++-------------------------------------- 1 file changed, 225 insertions(+), 768 deletions(-) diff --git a/BENCHMARKS.md b/BENCHMARKS.md index fc24af68..111e04ad 100644 --- a/BENCHMARKS.md +++ b/BENCHMARKS.md @@ -11,824 +11,281 @@ ## Table of Contents +- [Summary](#summary) - [Memory Consumption](#memory-consumption) -- [Benchmark Summary](#benchmark-summary) - - [GitHub API (203 routes)](#github-api-all-routes) - - [Google+ API (13 routes)](#google-api-all-routes) - - [Parse API (26 routes)](#parse-api-all-routes) - - [Static Routes (157 routes)](#static-routes-all) +- [Benchmark Results](#benchmark-results) + - [GitHub API (203 routes)](#github-api-203-routes) + - [Google+ API (13 routes)](#google-api-13-routes) + - [Parse API (26 routes)](#parse-api-26-routes) + - [Static Routes (157 routes)](#static-routes-157-routes) - [Micro Benchmarks](#micro-benchmarks) -- [Full Benchmark Results](#full-benchmark-results) + - [Single Param](#single-param) + - [5 Params](#5-params) + - [20 Params](#20-params) + - [Param Write](#param-write) + +--- + +## Summary + +The table below ranks all routers by **GitHub API throughput** (203 routes, all methods), which best represents real-world routing workloads. _Lower ns/op is better._ + +| Rank | Router | ns/op | B/op | allocs/op | Zero-alloc | +| :--: | :------------ | --------: | --------: | --------: | :----------------: | +| 1 | **Gin** | 9,944 | 0 | 0 | :white_check_mark: | +| 2 | **BunRouter** | 10,281 | 0 | 0 | :white_check_mark: | +| 3 | **Echo** | 11,072 | 0 | 0 | :white_check_mark: | +| 4 | HttpRouter | 15,059 | 13,792 | 167 | | +| 5 | HttpTreeMux | 49,302 | 65,856 | 671 | | +| 6 | Chi | 94,376 | 130,817 | 740 | | +| 7 | Beego | 101,941 | 71,456 | 609 | | +| 8 | Fiber | 109,148 | 0 | 0 | :white_check_mark: | +| 9 | Macaron | 121,785 | 147,784 | 1,624 | | +| 10 | Goji v2 | 242,849 | 313,744 | 3,712 | | +| 11 | GoRestful | 885,678 | 1,006,744 | 3,009 | | +| 12 | GorillaMux | 1,316,844 | 225,667 | 1,588 | | + +**Key takeaways:** + +- **Gin**, **BunRouter**, and **Echo** form the top tier — all achieve zero heap allocations and route the full GitHub API in ~10 us. +- **HttpRouter** remains extremely fast but incurs 1 alloc per parameterized route (167 allocs for 203 routes). +- **Fiber** also achieves zero allocations, but its fasthttp-based benchmark infrastructure adds per-iteration reset overhead — do not compare its absolute ns/op directly with net/http routers. +- **GorillaMux** and **GoRestful** are feature-rich but orders of magnitude slower, making them less suitable for latency-sensitive applications. + +> **Fiber caveat:** Fiber benchmarks use `fasthttp.RequestCtx` with per-iteration Reset, which adds constant overhead not present in net/http benchmarks. Fiber-vs-Fiber comparisons are valid; cross-framework comparisons should be interpreted with care. --- ## Memory Consumption -Memory required for loading the routing structure (lower is better). +Memory required for loading the routing structure (lower is better). Sorted by bytes ascending. ### Static Routes: 157 -| Router | Bytes | -|:-------|------:| -| **Denco** | **9,928** | -| **Pat** | **20,200** | +| Router | Bytes | +| :------------- | ---------: | | **HttpRouter** | **21,680** | -| GowwwRouter | 24,512 | -| R2router | 23,256 | -| Rivet | 24,608 | -| Aero | 28,728 | -| Tango | 28,296 | -| Bear | 29,984 | -| Goji | 27,216 | -| Ace | 30,648 | -| LARS | 30,640 | -| Gin | 34,408 | -| Macaron | 36,976 | -| Bone | 40,480 | -| GocraftWeb | 55,088 | -| HttpServeMux | 71,728 | -| HttpTreeMux | 73,448 | -| TigerTonic | 78,328 | -| Chi | 83,160 | -| Possum | 88,672 | -| Echo | 91,976 | -| Beego | 98,824 | -| Gojiv2 | 117,952 | -| Kocha | 123,160 | -| GoJsonRest | 136,296 | -| Martini | 314,360 | -| Vulcan | 367,064 | -| Traffic | 555,248 | -| GorillaMux | 599,496 | -| GoRestful | 819,704 | +| **Gin** | **34,408** | +| **Macaron** | **36,976** | +| BunRouter | 51,232 | +| Fiber | 59,248 | +| HttpServeMux | 71,728 | +| HttpTreeMux | 73,448 | +| Chi | 83,160 | +| Echo | 91,976 | +| Beego | 98,824 | +| Goji v2 | 117,952 | +| GorillaMux | 599,496 | +| GoRestful | 819,704 | ### GitHub API Routes: 203 -| Router | Bytes | -|:-------|------:| -| **Pat** | **19,400** | -| **Denco** | **35,360** | -| **HttpRouter** | **37,072** | -| Rivet | 42,840 | -| Goji | 46,416 | -| R2router | 46,616 | -| Ace | 48,616 | -| LARS | 48,592 | -| Tango | 54,872 | -| Gin | 58,840 | -| Bear | 80,528 | -| Possum | 81,832 | -| GowwwRouter | 86,656 | -| HttpTreeMux | 78,800 | -| Macaron | 90,632 | -| GocraftWeb | 93,896 | -| Chi | 94,888 | -| TigerTonic | 95,104 | -| Bone | 100,080 | -| Echo | 117,784 | -| Gojiv2 | 118,640 | -| GoJsonRest | 141,120 | -| Beego | 150,840 | -| Martini | 474,792 | -| Aero | 524,992 | -| Kocha | 784,144 | -| Traffic | 916,720 | -| GoRestful | 1,270,720 | -| GorillaMux | 1,319,696 | -| Vulcan | 423,216 | +| Router | Bytes | +| :-------------- | ---------: | +| **HttpRouter** | **37,072** | +| **Gin** | **58,840** | +| **HttpTreeMux** | **78,800** | +| Macaron | 90,632 | +| BunRouter | 93,776 | +| Chi | 94,888 | +| Echo | 117,784 | +| Goji v2 | 118,640 | +| Beego | 150,840 | +| Fiber | 163,832 | +| GoRestful | 1,270,848 | +| GorillaMux | 1,319,696 | ### Google+ API Routes: 13 -| Router | Bytes | -|:-------|------:| -| **Pat** | **1,848** | +| Router | Bytes | +| :------------- | --------: | | **HttpRouter** | **2,776** | -| **Goji** | **2,928** | -| Rivet | 3,064 | -| Denco | 3,224 | -| Ace | 3,680 | -| LARS | 3,656 | -| R2router | 3,864 | -| Gin | 4,576 | -| Tango | 5,200 | -| GowwwRouter | 6,168 | -| Bone | 6,688 | -| Bear | 7,096 | -| GocraftWeb | 7,480 | -| HttpTreeMux | 7,440 | -| Gojiv2 | 8,096 | -| Chi | 8,008 | -| Macaron | 8,672 | -| TigerTonic | 9,392 | -| Echo | 10,968 | -| Beego | 10,256 | -| GoJsonRest | 11,432 | -| Martini | 24,656 | -| Aero | 25,744 | -| Vulcan | 25,448 | -| Traffic | 48,176 | -| GorillaMux | 68,000 | -| GoRestful | 72,536 | -| Kocha | 128,880 | -| Possum | 7,192 | +| **Gin** | **4,576** | +| **BunRouter** | **7,360** | +| HttpTreeMux | 7,440 | +| Chi | 8,008 | +| Goji v2 | 8,096 | +| Macaron | 8,672 | +| Beego | 10,256 | +| Fiber | 10,840 | +| Echo | 10,968 | +| GorillaMux | 68,000 | +| GoRestful | 72,536 | ### Parse API Routes: 26 -| Router | Bytes | -|:-------|------:| -| **Pat** | **2,552** | -| **Denco** | **4,080** | -| **HttpRouter** | **5,024** | -| Goji | 5,248 | -| Rivet | 5,680 | -| Ace | 6,656 | -| LARS | 6,632 | -| R2router | 6,920 | -| Gin | 7,896 | -| HttpTreeMux | 7,848 | -| Possum | 8,104 | -| Bear | 12,256 | -| Tango | 8,952 | -| Chi | 9,656 | -| GowwwRouter | 10,048 | -| TigerTonic | 9,808 | -| Bone | 11,440 | -| GocraftWeb | 12,752 | -| Echo | 13,816 | -| Macaron | 13,704 | -| GoJsonRest | 14,112 | -| Gojiv2 | 16,064 | -| Beego | 19,256 | -| Aero | 28,152 | -| Martini | 43,760 | -| Traffic | 78,832 | -| Vulcan | 44,024 | -| GorillaMux | 105,384 | -| GoRestful | 121,200 | -| Kocha | 181,712 | +| Router | Bytes | +| :-------------- | --------: | +| **HttpRouter** | **5,024** | +| **Gin** | **7,896** | +| **HttpTreeMux** | **7,848** | +| BunRouter | 9,336 | +| Chi | 9,656 | +| Echo | 13,816 | +| Macaron | 13,704 | +| Fiber | 15,352 | +| Goji v2 | 16,064 | +| Beego | 19,256 | +| GorillaMux | 105,384 | +| GoRestful | 121,200 | --- -## Benchmark Summary +## Benchmark Results -The tables below highlight the **top performers** across each major API benchmark. -Gin consistently ranks among the fastest routers with **zero memory allocations**. - -### GitHub API (All Routes) +### GitHub API (203 routes) Routing all 203 GitHub API endpoints per operation. -| Rank | Router | Time (ns/op) | Bytes (B/op) | Allocs/op | -|:----:|:-------|-------------:|-------------:|----------:| -| 1 | **Aero** | 6,646 | 0 | 0 | -| 2 | **LARS** | 8,714 | 0 | 0 | -| 3 | **Gin** | 9,058 | 0 | 0 | -| 4 | Echo | 12,030 | 0 | 0 | -| 5 | HttpRouter | 13,840 | 13,792 | 167 | -| 6 | Ace | 21,354 | 13,792 | 167 | -| 7 | Denco | 22,401 | 20,224 | 167 | -| 8 | Rivet | 23,337 | 16,272 | 167 | -| 9 | Kocha | 33,213 | 20,592 | 504 | -| 10 | GowwwRouter | 35,511 | 61,456 | 334 | -| ... | ... | ... | ... | ... | -| 28 | GorillaMux | 1,282,012 | 225,666 | 1,588 | -| 29 | Pat | 1,432,291 | 1,421,792 | 23,019 | -| 30 | Martini | 1,483,537 | 231,418 | 2,731 | +| Rank | Router | ns/op | B/op | allocs/op | +| :--: | :------------ | --------: | --------: | --------: | +| 1 | **Gin** | 9,944 | 0 | 0 | +| 2 | **BunRouter** | 10,281 | 0 | 0 | +| 3 | **Echo** | 11,072 | 0 | 0 | +| 4 | HttpRouter | 15,059 | 13,792 | 167 | +| 5 | HttpTreeMux | 49,302 | 65,856 | 671 | +| 6 | Chi | 94,376 | 130,817 | 740 | +| 7 | Beego | 101,941 | 71,456 | 609 | +| 8 | Fiber | 109,148 | 0 | 0 | +| 9 | Macaron | 121,785 | 147,784 | 1,624 | +| 10 | Goji v2 | 242,849 | 313,744 | 3,712 | +| 11 | GoRestful | 885,678 | 1,006,744 | 3,009 | +| 12 | GorillaMux | 1,316,844 | 225,667 | 1,588 | -### Google+ API (All Routes) +### Google+ API (13 routes) Routing all 13 Google+ API endpoints per operation. -| Rank | Router | Time (ns/op) | Bytes (B/op) | Allocs/op | -|:----:|:-------|-------------:|-------------:|----------:| -| 1 | **Aero** | 323.2 | 0 | 0 | -| 2 | **LARS** | 382.6 | 0 | 0 | -| 3 | **Gin** | 412.3 | 0 | 0 | -| 4 | Echo | 426.0 | 0 | 0 | -| 5 | HttpRouter | 649.1 | 640 | 11 | -| 6 | Denco | 910.9 | 672 | 11 | -| 7 | Ace | 912.1 | 640 | 11 | -| 8 | Rivet | 928.1 | 768 | 11 | -| 9 | Kocha | 1,323 | 848 | 27 | -| 10 | GowwwRouter | 1,858 | 4,048 | 22 | -| ... | ... | ... | ... | ... | -| 28 | Traffic | 22,350 | 26,616 | 366 | -| 29 | GoRestful | 23,142 | 60,720 | 193 | -| 30 | Martini | 24,600 | 14,328 | 171 | +| Rank | Router | ns/op | B/op | allocs/op | +| :--: | :------------ | -----: | -----: | --------: | +| 1 | **BunRouter** | 348.5 | 0 | 0 | +| 2 | **Gin** | 429.7 | 0 | 0 | +| 3 | **Echo** | 451.1 | 0 | 0 | +| 4 | HttpRouter | 668.6 | 640 | 11 | +| 5 | HttpTreeMux | 2,428 | 4,032 | 38 | +| 6 | Fiber | 2,506 | 0 | 0 | +| 7 | Chi | 5,333 | 8,480 | 48 | +| 8 | Beego | 5,927 | 4,576 | 39 | +| 9 | Macaron | 7,294 | 9,464 | 104 | +| 10 | Goji v2 | 8,000 | 15,120 | 115 | +| 11 | GorillaMux | 14,707 | 14,448 | 102 | +| 12 | GoRestful | 24,189 | 60,720 | 193 | -### Parse API (All Routes) +### Parse API (26 routes) Routing all 26 Parse API endpoints per operation. -| Rank | Router | Time (ns/op) | Bytes (B/op) | Allocs/op | -|:----:|:-------|-------------:|-------------:|----------:| -| 1 | **Aero** | 546.0 | 0 | 0 | -| 2 | **LARS** | 669.4 | 0 | 0 | -| 3 | **Gin** | 719.8 | 0 | 0 | -| 4 | Echo | 723.0 | 0 | 0 | -| 5 | HttpRouter | 921.5 | 640 | 16 | -| 6 | Denco | 1,291 | 928 | 16 | -| 7 | Rivet | 1,385 | 912 | 16 | -| 8 | Ace | 1,445 | 640 | 16 | -| 9 | Kocha | 1,813 | 960 | 35 | -| 10 | GowwwRouter | 2,924 | 5,888 | 32 | -| ... | ... | ... | ... | ... | -| 28 | Traffic | 34,164 | 45,760 | 630 | -| 29 | Martini | 39,785 | 25,696 | 305 | -| 30 | GoRestful | 52,633 | 131,728 | 380 | +| Rank | Router | ns/op | B/op | allocs/op | +| :--: | :------------ | -----: | ------: | --------: | +| 1 | **BunRouter** | 588.2 | 0 | 0 | +| 2 | **Gin** | 712.1 | 0 | 0 | +| 3 | **Echo** | 742.1 | 0 | 0 | +| 4 | HttpRouter | 948.5 | 640 | 16 | +| 5 | HttpTreeMux | 3,372 | 5,728 | 51 | +| 6 | Fiber | 4,250 | 0 | 0 | +| 7 | Chi | 8,863 | 14,944 | 84 | +| 8 | Beego | 10,541 | 9,152 | 78 | +| 9 | Macaron | 13,635 | 18,928 | 208 | +| 10 | Goji v2 | 13,264 | 29,456 | 199 | +| 11 | GorillaMux | 25,886 | 26,960 | 198 | +| 12 | GoRestful | 54,780 | 131,728 | 380 | -### Static Routes (All) +### Static Routes (157 routes) -Routing all 157 static routes per operation. +Routing all 157 static routes per operation. Includes http.ServeMux as baseline. -| Rank | Router | Time (ns/op) | Bytes (B/op) | Allocs/op | -|:----:|:-------|-------------:|-------------:|----------:| -| 1 | **Denco** | 2,240 | 0 | 0 | -| 2 | **Aero** | 2,872 | 0 | 0 | -| 3 | **HttpTreeMux** | 4,031 | 0 | 0 | -| 4 | HttpRouter | 4,095 | 0 | 0 | -| 5 | LARS | 5,272 | 0 | 0 | -| 6 | Gin | 5,566 | 0 | 0 | -| 7 | Ace | 5,981 | 0 | 0 | -| 8 | Kocha | 6,013 | 0 | 0 | -| 9 | GowwwRouter | 6,622 | 0 | 0 | -| 10 | Echo | 6,714 | 0 | 0 | -| ... | ... | ... | ... | ... | -| 28 | Martini | 577,268 | 129,209 | 2,031 | -| 29 | Traffic | 699,470 | 749,837 | 14,444 | -| 30 | Pat | 813,157 | 602,832 | 12,559 | +| Rank | Router | ns/op | B/op | allocs/op | +| :--: | :-------------- | ------: | ------: | --------: | +| 1 | **HttpRouter** | 4,177 | 0 | 0 | +| 2 | **HttpTreeMux** | 5,363 | 0 | 0 | +| 3 | **Gin** | 5,528 | 0 | 0 | +| 4 | BunRouter | 5,997 | 0 | 0 | +| 5 | Echo | 6,897 | 0 | 0 | +| — | HttpServeMux | 18,172 | 0 | 0 | +| 6 | Fiber | 29,310 | 0 | 0 | +| 7 | Chi | 41,317 | 57,776 | 314 | +| 8 | Beego | 68,255 | 55,264 | 471 | +| 9 | Macaron | 81,824 | 114,296 | 1,256 | +| 10 | Goji v2 | 84,459 | 175,840 | 1,099 | +| 11 | GorillaMux | 302,825 | 133,137 | 1,099 | +| 12 | GoRestful | 436,510 | 677,824 | 2,193 | --- ## Micro Benchmarks -### Single Parameter +### Single Param -``` -BenchmarkGin_Param 50441539 24.05 ns/op 0 B/op 0 allocs/op -BenchmarkAce_Param 24363132 50.00 ns/op 32 B/op 1 allocs/op -BenchmarkAero_Param 77342221 15.49 ns/op 0 B/op 0 allocs/op -BenchmarkBear_Param 4424601 271.1 ns/op 456 B/op 5 allocs/op -BenchmarkBeego_Param 3209640 381.4 ns/op 352 B/op 3 allocs/op -BenchmarkBone_Param 2987578 432.5 ns/op 752 B/op 5 allocs/op -BenchmarkChi_Param 3111004 358.4 ns/op 704 B/op 4 allocs/op -BenchmarkDenco_Param 28276489 40.28 ns/op 32 B/op 1 allocs/op -BenchmarkEcho_Param 65189638 18.99 ns/op 0 B/op 0 allocs/op -BenchmarkGocraftWeb_Param 3556015 340.4 ns/op 624 B/op 7 allocs/op -BenchmarkGoji_Param 6142947 198.9 ns/op 336 B/op 2 allocs/op -BenchmarkGojiv2_Param 2446671 540.1 ns/op 1136 B/op 8 allocs/op -BenchmarkGoJsonRest_Param 2730858 419.8 ns/op 617 B/op 13 allocs/op -BenchmarkGoRestful_Param 784556 1549 ns/op 4600 B/op 15 allocs/op -BenchmarkGorillaMux_Param 1857164 650.0 ns/op 1152 B/op 8 allocs/op -BenchmarkGowwwRouter_Param 8161994 147.8 ns/op 368 B/op 2 allocs/op -BenchmarkHttpRouter_Param 35229486 31.71 ns/op 32 B/op 1 allocs/op -BenchmarkHttpTreeMux_Param 6598603 186.5 ns/op 352 B/op 3 allocs/op -BenchmarkKocha_Param 18681621 61.98 ns/op 48 B/op 2 allocs/op -BenchmarkLARS_Param 60355720 20.04 ns/op 0 B/op 0 allocs/op -BenchmarkMacaron_Param 1669972 725.6 ns/op 1064 B/op 10 allocs/op -BenchmarkMartini_Param 993966 1343 ns/op 1096 B/op 12 allocs/op -BenchmarkPat_Param 2232280 481.9 ns/op 552 B/op 12 allocs/op -BenchmarkPossum_Param 3422949 349.7 ns/op 496 B/op 5 allocs/op -BenchmarkR2router_Param 6040192 198.3 ns/op 400 B/op 4 allocs/op -BenchmarkRivet_Param 25981898 46.35 ns/op 48 B/op 1 allocs/op -BenchmarkTango_Param 4682972 249.3 ns/op 192 B/op 6 allocs/op -BenchmarkTigerTonic_Param 1715374 688.0 ns/op 744 B/op 16 allocs/op -BenchmarkTraffic_Param 938739 1240 ns/op 1888 B/op 23 allocs/op -BenchmarkVulcan_Param 9498867 124.1 ns/op 98 B/op 3 allocs/op -``` +Route: `/user/:name` — Request: `GET /user/gordon` -### 5 Parameters +| Rank | Router | ns/op | B/op | allocs/op | +| :--: | :------------ | ----: | ----: | --------: | +| 1 | **BunRouter** | 12.22 | 0 | 0 | +| 2 | **Echo** | 17.75 | 0 | 0 | +| 3 | **Gin** | 23.31 | 0 | 0 | +| 4 | HttpRouter | 31.88 | 32 | 1 | +| 5 | Fiber | 114.4 | 0 | 0 | +| 6 | HttpTreeMux | 165.0 | 352 | 3 | +| 7 | Chi | 332.2 | 704 | 4 | +| 8 | Beego | 348.8 | 352 | 3 | +| 9 | Goji v2 | 494.3 | 1,136 | 8 | +| 10 | GorillaMux | 630.6 | 1,152 | 8 | +| 11 | Macaron | 708.0 | 1,064 | 10 | +| 12 | GoRestful | 1,394 | 4,600 | 15 | -``` -BenchmarkGin_Param5 30261015 38.89 ns/op 0 B/op 0 allocs/op -BenchmarkAce_Param5 11764478 100.2 ns/op 160 B/op 1 allocs/op -BenchmarkAero_Param5 33756498 34.24 ns/op 0 B/op 0 allocs/op -BenchmarkBear_Param5 3066855 387.5 ns/op 501 B/op 5 allocs/op -BenchmarkBeego_Param5 2459563 495.6 ns/op 352 B/op 3 allocs/op -BenchmarkBone_Param5 1000000 1042 ns/op 1232 B/op 10 allocs/op -BenchmarkChi_Param5 2523159 469.0 ns/op 704 B/op 4 allocs/op -BenchmarkDenco_Param5 8588504 130.9 ns/op 160 B/op 1 allocs/op -BenchmarkEcho_Param5 22098444 49.58 ns/op 0 B/op 0 allocs/op -BenchmarkGocraftWeb_Param5 2255988 522.1 ns/op 920 B/op 11 allocs/op -BenchmarkGoji_Param5 4107170 283.3 ns/op 336 B/op 2 allocs/op -BenchmarkGojiv2_Param5 1691694 706.7 ns/op 1248 B/op 10 allocs/op -BenchmarkGoJsonRest_Param5 1579816 736.0 ns/op 1073 B/op 16 allocs/op -BenchmarkGoRestful_Param5 495588 2283 ns/op 5400 B/op 15 allocs/op -BenchmarkGorillaMux_Param5 734078 1488 ns/op 1184 B/op 8 allocs/op -BenchmarkGowwwRouter_Param5 7023253 171.0 ns/op 368 B/op 2 allocs/op -BenchmarkHttpRouter_Param5 16128580 71.82 ns/op 160 B/op 1 allocs/op -BenchmarkHttpTreeMux_Param5 2799802 421.4 ns/op 576 B/op 6 allocs/op -BenchmarkKocha_Param5 5397548 216.4 ns/op 304 B/op 6 allocs/op -BenchmarkLARS_Param5 31268811 38.98 ns/op 0 B/op 0 allocs/op -BenchmarkMacaron_Param5 1246534 934.2 ns/op 1064 B/op 10 allocs/op -BenchmarkMartini_Param5 523628 2384 ns/op 1256 B/op 13 allocs/op -BenchmarkPat_Param5 726936 1592 ns/op 944 B/op 32 allocs/op -BenchmarkPossum_Param5 3320758 356.0 ns/op 496 B/op 5 allocs/op -BenchmarkR2router_Param5 3726697 312.7 ns/op 432 B/op 5 allocs/op -BenchmarkRivet_Param5 8050082 145.0 ns/op 240 B/op 1 allocs/op -BenchmarkTango_Param5 3265436 366.0 ns/op 392 B/op 6 allocs/op -BenchmarkTigerTonic_Param5 469060 2632 ns/op 2408 B/op 41 allocs/op -BenchmarkTraffic_Param5 425434 2722 ns/op 2280 B/op 31 allocs/op -BenchmarkVulcan_Param5 5213118 241.1 ns/op 98 B/op 3 allocs/op -``` +### 5 Params -### 20 Parameters +Route: `/:a/:b/:c/:d/:e` — Request: `GET /test/test/test/test/test` -``` -BenchmarkGin_Param20 13291521 89.03 ns/op 0 B/op 0 allocs/op -BenchmarkAce_Param20 4432400 265.2 ns/op 640 B/op 1 allocs/op -BenchmarkAero_Param20 10534245 111.3 ns/op 0 B/op 0 allocs/op -BenchmarkBear_Param20 1000000 1027 ns/op 1665 B/op 5 allocs/op -BenchmarkBeego_Param20 1398088 856.2 ns/op 352 B/op 3 allocs/op -BenchmarkBone_Param20 275770 4416 ns/op 4368 B/op 32 allocs/op -BenchmarkChi_Param20 1000000 1111 ns/op 704 B/op 4 allocs/op -BenchmarkDenco_Param20 2717076 430.2 ns/op 640 B/op 1 allocs/op -BenchmarkEcho_Param20 7671782 152.3 ns/op 0 B/op 0 allocs/op -BenchmarkGocraftWeb_Param20 672906 1633 ns/op 3795 B/op 15 allocs/op -BenchmarkGoji_Param20 1000000 1001 ns/op 1247 B/op 2 allocs/op -BenchmarkGojiv2_Param20 760102 1528 ns/op 1568 B/op 12 allocs/op -BenchmarkGoJsonRest_Param20 516908 2099 ns/op 3539 B/op 24 allocs/op -BenchmarkGoRestful_Param20 196784 5920 ns/op 8520 B/op 15 allocs/op -BenchmarkGorillaMux_Param20 307082 3793 ns/op 3483 B/op 10 allocs/op -BenchmarkGowwwRouter_Param20 5098538 254.1 ns/op 368 B/op 2 allocs/op -BenchmarkHttpRouter_Param20 5192563 230.2 ns/op 640 B/op 1 allocs/op -BenchmarkHttpTreeMux_Param20 471916 3085 ns/op 3168 B/op 10 allocs/op -BenchmarkKocha_Param20 1429558 831.6 ns/op 1264 B/op 12 allocs/op -BenchmarkLARS_Param20 13176316 90.49 ns/op 0 B/op 0 allocs/op -BenchmarkMacaron_Param20 498850 2459 ns/op 2680 B/op 12 allocs/op -BenchmarkMartini_Param20 124274 10258 ns/op 3668 B/op 15 allocs/op -BenchmarkPat_Param20 454987 2592 ns/op 1640 B/op 44 allocs/op -BenchmarkPossum_Param20 3251416 383.8 ns/op 496 B/op 5 allocs/op -BenchmarkR2router_Param20 908521 1291 ns/op 2176 B/op 7 allocs/op -BenchmarkRivet_Param20 1000000 1027 ns/op 1024 B/op 1 allocs/op -BenchmarkTango_Param20 992810 1123 ns/op 952 B/op 6 allocs/op -BenchmarkTigerTonic_Param20 121791 9949 ns/op 10248 B/op 111 allocs/op -BenchmarkTraffic_Param20 119523 10037 ns/op 7784 B/op 56 allocs/op -BenchmarkVulcan_Param20 2427007 504.5 ns/op 98 B/op 3 allocs/op -``` +| Rank | Router | ns/op | B/op | allocs/op | +| :--: | :------------ | ----: | ----: | --------: | +| 1 | **BunRouter** | 41.86 | 0 | 0 | +| 2 | **Echo** | 43.76 | 0 | 0 | +| 3 | **Gin** | 44.20 | 0 | 0 | +| 4 | HttpRouter | 83.74 | 160 | 1 | +| 5 | Fiber | 271.6 | 0 | 0 | +| 6 | HttpTreeMux | 358.8 | 576 | 6 | +| 7 | Chi | 453.7 | 704 | 4 | +| 8 | Beego | 480.3 | 352 | 3 | +| 9 | Goji v2 | 532.4 | 1,200 | 8 | +| 10 | Macaron | 799.7 | 1,064 | 10 | +| 11 | GorillaMux | 972.6 | 1,216 | 8 | +| 12 | GoRestful | 1,579 | 4,712 | 15 | + +### 20 Params + +Route: `/:a/:b/.../:t` (20 segments) — Request: `GET /a/b/.../t` + +| Rank | Router | ns/op | B/op | allocs/op | +| :--: | :------------ | ----: | ----: | --------: | +| 1 | **Gin** | 121.7 | 0 | 0 | +| 2 | **Echo** | 127.5 | 0 | 0 | +| 3 | **BunRouter** | 211.4 | 0 | 0 | +| 4 | HttpRouter | 290.2 | 704 | 1 | +| 5 | Fiber | 466.1 | 0 | 0 | +| 6 | Goji v2 | 745.3 | 1,440 | 8 | +| 7 | Beego | 1,099 | 352 | 3 | +| 8 | Chi | 1,805 | 2,504 | 9 | +| 9 | HttpTreeMux | 1,857 | 3,144 | 13 | +| 10 | Macaron | 2,058 | 2,864 | 15 | +| 11 | GorillaMux | 2,223 | 3,272 | 13 | +| 12 | GoRestful | 3,337 | 7,008 | 20 | ### Param Write -``` -BenchmarkGin_ParamWrite 23316990 50.84 ns/op 0 B/op 0 allocs/op -BenchmarkAce_ParamWrite 13474160 92.09 ns/op 40 B/op 2 allocs/op -BenchmarkAero_ParamWrite 34476930 33.00 ns/op 0 B/op 0 allocs/op -BenchmarkBear_ParamWrite 3806036 310.0 ns/op 456 B/op 5 allocs/op -BenchmarkBeego_ParamWrite 2834390 419.9 ns/op 360 B/op 4 allocs/op -BenchmarkBone_ParamWrite 2627498 466.8 ns/op 752 B/op 5 allocs/op -BenchmarkChi_ParamWrite 3128284 371.5 ns/op 704 B/op 4 allocs/op -BenchmarkDenco_ParamWrite 16741923 71.49 ns/op 32 B/op 1 allocs/op -BenchmarkEcho_ParamWrite 29455958 37.94 ns/op 8 B/op 1 allocs/op -BenchmarkGocraftWeb_ParamWrite 2992538 393.9 ns/op 648 B/op 8 allocs/op -BenchmarkGoji_ParamWrite 4816736 250.7 ns/op 336 B/op 2 allocs/op -BenchmarkGojiv2_ParamWrite 2044604 590.6 ns/op 1152 B/op 9 allocs/op -BenchmarkGoJsonRest_ParamWrite 2149220 544.9 ns/op 1064 B/op 18 allocs/op -BenchmarkGoRestful_ParamWrite 633780 1853 ns/op 4616 B/op 16 allocs/op -BenchmarkGorillaMux_ParamWrite 1652036 727.3 ns/op 1160 B/op 9 allocs/op -BenchmarkGowwwRouter_ParamWrite 4195808 279.1 ns/op 392 B/op 3 allocs/op -BenchmarkHttpRouter_ParamWrite 21606003 54.14 ns/op 32 B/op 1 allocs/op -BenchmarkHttpTreeMux_ParamWrite 5398851 224.9 ns/op 352 B/op 3 allocs/op -BenchmarkKocha_ParamWrite 14068706 83.18 ns/op 48 B/op 2 allocs/op -BenchmarkLARS_ParamWrite 25768928 47.62 ns/op 0 B/op 0 allocs/op -BenchmarkMacaron_ParamWrite 1355762 894.2 ns/op 1152 B/op 13 allocs/op -BenchmarkMartini_ParamWrite 514706 2544 ns/op 1224 B/op 16 allocs/op -BenchmarkPat_ParamWrite 1285564 880.5 ns/op 1040 B/op 17 allocs/op -BenchmarkPossum_ParamWrite 3127676 383.7 ns/op 496 B/op 5 allocs/op -BenchmarkR2router_ParamWrite 4948783 234.5 ns/op 400 B/op 4 allocs/op -BenchmarkRivet_ParamWrite 9561326 125.0 ns/op 112 B/op 2 allocs/op -BenchmarkTango_ParamWrite 3855218 308.3 ns/op 280 B/op 7 allocs/op -BenchmarkTigerTonic_ParamWrite 1000000 1090 ns/op 1024 B/op 18 allocs/op -BenchmarkTraffic_ParamWrite 742009 1523 ns/op 2248 B/op 25 allocs/op -BenchmarkVulcan_ParamWrite 6929622 170.7 ns/op 98 B/op 3 allocs/op -``` +Route: `/user/:name` with response write — Request: `GET /user/gordon` ---- - -## Full Benchmark Results - -### GitHub API - -#### Static - -``` -BenchmarkGin_GithubStatic 43895277 28.10 ns/op 0 B/op 0 allocs/op -BenchmarkAce_GithubStatic 42779731 28.31 ns/op 0 B/op 0 allocs/op -BenchmarkAero_GithubStatic 83284414 14.50 ns/op 0 B/op 0 allocs/op -BenchmarkBear_GithubStatic 9311720 131.2 ns/op 120 B/op 3 allocs/op -BenchmarkBeego_GithubStatic 2897301 395.7 ns/op 352 B/op 3 allocs/op -BenchmarkBone_GithubStatic 308800 3903 ns/op 2880 B/op 60 allocs/op -BenchmarkChi_GithubStatic 5401872 229.6 ns/op 368 B/op 2 allocs/op -BenchmarkDenco_GithubStatic 98722773 11.71 ns/op 0 B/op 0 allocs/op -BenchmarkEcho_GithubStatic 40625690 27.23 ns/op 0 B/op 0 allocs/op -BenchmarkGocraftWeb_GithubStatic 5341020 229.8 ns/op 288 B/op 5 allocs/op -BenchmarkGoji_GithubStatic 15548287 76.12 ns/op 0 B/op 0 allocs/op -BenchmarkGojiv2_GithubStatic 2520218 490.3 ns/op 1120 B/op 7 allocs/op -BenchmarkGoJsonRest_GithubStatic 3861292 321.3 ns/op 297 B/op 11 allocs/op -BenchmarkGoRestful_GithubStatic 330211 3671 ns/op 4792 B/op 14 allocs/op -BenchmarkGorillaMux_GithubStatic 938425 1474 ns/op 848 B/op 7 allocs/op -BenchmarkGowwwRouter_GithubStatic 38324576 32.24 ns/op 0 B/op 0 allocs/op -BenchmarkHttpRouter_GithubStatic 69731800 17.26 ns/op 0 B/op 0 allocs/op -BenchmarkHttpTreeMux_GithubStatic 55391751 22.97 ns/op 0 B/op 0 allocs/op -BenchmarkKocha_GithubStatic 52384971 24.34 ns/op 0 B/op 0 allocs/op -BenchmarkLARS_GithubStatic 45034478 25.48 ns/op 0 B/op 0 allocs/op -BenchmarkMacaron_GithubStatic 2014342 578.0 ns/op 728 B/op 8 allocs/op -BenchmarkMartini_GithubStatic 554347 2686 ns/op 792 B/op 11 allocs/op -BenchmarkPat_GithubStatic 288867 4049 ns/op 3648 B/op 76 allocs/op -BenchmarkPossum_GithubStatic 3928141 306.4 ns/op 416 B/op 3 allocs/op -BenchmarkR2router_GithubStatic 11773146 97.06 ns/op 112 B/op 3 allocs/op -BenchmarkRivet_GithubStatic 37206849 32.03 ns/op 0 B/op 0 allocs/op -BenchmarkTango_GithubStatic 3806214 321.1 ns/op 192 B/op 6 allocs/op -BenchmarkTigerTonic_GithubStatic 15421950 82.96 ns/op 48 B/op 1 allocs/op -BenchmarkTraffic_GithubStatic 307382 3618 ns/op 4632 B/op 89 allocs/op -BenchmarkVulcan_GithubStatic 6107649 198.2 ns/op 98 B/op 3 allocs/op -``` - -#### Param - -``` -BenchmarkGin_GithubParam 25399108 50.29 ns/op 0 B/op 0 allocs/op -BenchmarkAce_GithubParam 12033406 102.1 ns/op 96 B/op 1 allocs/op -BenchmarkAero_GithubParam 34218457 35.12 ns/op 0 B/op 0 allocs/op -BenchmarkBear_GithubParam 3491167 340.3 ns/op 496 B/op 5 allocs/op -BenchmarkBeego_GithubParam 2462625 492.9 ns/op 352 B/op 3 allocs/op -BenchmarkBone_GithubParam 479170 2435 ns/op 1824 B/op 18 allocs/op -BenchmarkChi_GithubParam 2392147 439.7 ns/op 704 B/op 4 allocs/op -BenchmarkDenco_GithubParam 10566573 108.5 ns/op 128 B/op 1 allocs/op -BenchmarkEcho_GithubParam 22438311 53.46 ns/op 0 B/op 0 allocs/op -BenchmarkGocraftWeb_GithubParam 2686350 425.8 ns/op 656 B/op 7 allocs/op -BenchmarkGoji_GithubParam 3468987 331.6 ns/op 336 B/op 2 allocs/op -BenchmarkGojiv2_GithubParam 1713819 693.3 ns/op 1216 B/op 10 allocs/op -BenchmarkGoJsonRest_GithubParam 2105818 561.9 ns/op 681 B/op 14 allocs/op -BenchmarkGoRestful_GithubParam 268806 4732 ns/op 4696 B/op 15 allocs/op -BenchmarkGorillaMux_GithubParam 484622 2436 ns/op 1168 B/op 8 allocs/op -BenchmarkGowwwRouter_GithubParam 6445003 195.4 ns/op 368 B/op 2 allocs/op -BenchmarkHttpRouter_GithubParam 14665429 88.59 ns/op 96 B/op 1 allocs/op -BenchmarkHttpTreeMux_GithubParam 4199426 311.2 ns/op 384 B/op 4 allocs/op -BenchmarkKocha_GithubParam 8478230 139.3 ns/op 112 B/op 3 allocs/op -BenchmarkLARS_GithubParam 27976429 43.36 ns/op 0 B/op 0 allocs/op -BenchmarkMacaron_GithubParam 1475805 805.7 ns/op 1064 B/op 10 allocs/op -BenchmarkMartini_GithubParam 354076 3459 ns/op 1176 B/op 13 allocs/op -BenchmarkPat_GithubParam 422454 2919 ns/op 2360 B/op 45 allocs/op -BenchmarkPossum_GithubParam 3345200 349.5 ns/op 496 B/op 5 allocs/op -BenchmarkR2router_GithubParam 5887364 205.1 ns/op 400 B/op 4 allocs/op -BenchmarkRivet_GithubParam 9056540 118.9 ns/op 96 B/op 1 allocs/op -BenchmarkTango_GithubParam 3217730 376.9 ns/op 296 B/op 6 allocs/op -BenchmarkTigerTonic_GithubParam 1000000 1043 ns/op 1072 B/op 21 allocs/op -BenchmarkTraffic_GithubParam 375636 3171 ns/op 2840 B/op 43 allocs/op -BenchmarkVulcan_GithubParam 3770610 321.0 ns/op 98 B/op 3 allocs/op -``` - -#### All Routes - -``` -BenchmarkGin_GithubAll 135811 9058 ns/op 0 B/op 0 allocs/op -BenchmarkAce_GithubAll 61230 21354 ns/op 13792 B/op 167 allocs/op -BenchmarkAero_GithubAll 176716 6646 ns/op 0 B/op 0 allocs/op -BenchmarkBear_GithubAll 16941 69598 ns/op 86448 B/op 943 allocs/op -BenchmarkBeego_GithubAll 12163 97593 ns/op 71456 B/op 609 allocs/op -BenchmarkBone_GithubAll 1176 1040342 ns/op 709472 B/op 8453 allocs/op -BenchmarkChi_GithubAll 12346 98943 ns/op 130816 B/op 740 allocs/op -BenchmarkDenco_GithubAll 59050 22401 ns/op 20224 B/op 167 allocs/op -BenchmarkEcho_GithubAll 104632 12030 ns/op 0 B/op 0 allocs/op -BenchmarkGocraftWeb_GithubAll 13927 85845 ns/op 123552 B/op 1400 allocs/op -BenchmarkGoji_GithubAll 8512 158755 ns/op 56112 B/op 334 allocs/op -BenchmarkGojiv2_GithubAll 5108 226986 ns/op 313744 B/op 3712 allocs/op -BenchmarkGoJsonRest_GithubAll 9859 120437 ns/op 127875 B/op 2737 allocs/op -BenchmarkGoRestful_GithubAll 1359 863892 ns/op 1006744 B/op 3009 allocs/op -BenchmarkGorillaMux_GithubAll 974 1282012 ns/op 225666 B/op 1588 allocs/op -BenchmarkGowwwRouter_GithubAll 32976 35511 ns/op 61456 B/op 334 allocs/op -BenchmarkHttpRouter_GithubAll 89264 13840 ns/op 13792 B/op 167 allocs/op -BenchmarkHttpTreeMux_GithubAll 25005 49430 ns/op 65856 B/op 671 allocs/op -BenchmarkKocha_GithubAll 38254 33213 ns/op 20592 B/op 504 allocs/op -BenchmarkLARS_GithubAll 144225 8714 ns/op 0 B/op 0 allocs/op -BenchmarkMacaron_GithubAll 8706 131574 ns/op 147784 B/op 1624 allocs/op -BenchmarkMartini_GithubAll 825 1483537 ns/op 231418 B/op 2731 allocs/op -BenchmarkPat_GithubAll 838 1432291 ns/op 1421792 B/op 23019 allocs/op -BenchmarkPossum_GithubAll 18913 62291 ns/op 84448 B/op 609 allocs/op -BenchmarkR2router_GithubAll 26276 45938 ns/op 70832 B/op 776 allocs/op -BenchmarkRivet_GithubAll 49792 23337 ns/op 16272 B/op 167 allocs/op -BenchmarkTango_GithubAll 14306 84094 ns/op 53850 B/op 1215 allocs/op -BenchmarkTigerTonic_GithubAll 5797 209921 ns/op 188584 B/op 4300 allocs/op -BenchmarkTraffic_GithubAll 1044 1213864 ns/op 829175 B/op 14582 allocs/op -BenchmarkVulcan_GithubAll 19022 60788 ns/op 19894 B/op 609 allocs/op -``` - -### Google+ API - -#### Static - -``` -BenchmarkGin_GPlusStatic 50430675 22.47 ns/op 0 B/op 0 allocs/op -BenchmarkAce_GPlusStatic 51961077 23.43 ns/op 0 B/op 0 allocs/op -BenchmarkAero_GPlusStatic 86196060 13.97 ns/op 0 B/op 0 allocs/op -BenchmarkBear_GPlusStatic 11848935 99.99 ns/op 104 B/op 3 allocs/op -BenchmarkBeego_GPlusStatic 3394909 360.2 ns/op 352 B/op 3 allocs/op -BenchmarkBone_GPlusStatic 21614740 54.72 ns/op 32 B/op 1 allocs/op -BenchmarkChi_GPlusStatic 5905422 202.2 ns/op 368 B/op 2 allocs/op -BenchmarkDenco_GPlusStatic 100000000 11.25 ns/op 0 B/op 0 allocs/op -BenchmarkEcho_GPlusStatic 63868430 18.64 ns/op 0 B/op 0 allocs/op -BenchmarkGocraftWeb_GPlusStatic 6419139 183.5 ns/op 272 B/op 5 allocs/op -BenchmarkGoji_GPlusStatic 26074863 46.67 ns/op 0 B/op 0 allocs/op -BenchmarkGojiv2_GPlusStatic 2529218 474.7 ns/op 1120 B/op 7 allocs/op -BenchmarkGoJsonRest_GPlusStatic 4662106 254.6 ns/op 297 B/op 11 allocs/op -BenchmarkGoRestful_GPlusStatic 782607 1489 ns/op 4272 B/op 14 allocs/op -BenchmarkGorillaMux_GPlusStatic 2741367 417.2 ns/op 848 B/op 7 allocs/op -BenchmarkGowwwRouter_GPlusStatic 100000000 11.61 ns/op 0 B/op 0 allocs/op -BenchmarkHttpRouter_GPlusStatic 123925137 9.716 ns/op 0 B/op 0 allocs/op -BenchmarkHttpTreeMux_GPlusStatic 84271881 14.55 ns/op 0 B/op 0 allocs/op -BenchmarkKocha_GPlusStatic 96201384 12.78 ns/op 0 B/op 0 allocs/op -BenchmarkLARS_GPlusStatic 60936904 19.79 ns/op 0 B/op 0 allocs/op -BenchmarkMacaron_GPlusStatic 2281216 523.1 ns/op 728 B/op 8 allocs/op -BenchmarkMartini_GPlusStatic 1000000 1158 ns/op 792 B/op 11 allocs/op -BenchmarkPat_GPlusStatic 12473952 94.32 ns/op 96 B/op 2 allocs/op -BenchmarkPossum_GPlusStatic 4341033 283.0 ns/op 416 B/op 3 allocs/op -BenchmarkR2router_GPlusStatic 14272594 80.44 ns/op 112 B/op 3 allocs/op -BenchmarkRivet_GPlusStatic 64791607 18.26 ns/op 0 B/op 0 allocs/op -BenchmarkTango_GPlusStatic 5208178 231.0 ns/op 152 B/op 6 allocs/op -BenchmarkTigerTonic_GPlusStatic 26052549 45.54 ns/op 32 B/op 1 allocs/op -BenchmarkTraffic_GPlusStatic 1655068 664.6 ns/op 1080 B/op 15 allocs/op -BenchmarkVulcan_GPlusStatic 10144974 117.5 ns/op 98 B/op 3 allocs/op -``` - -#### Param - -``` -BenchmarkGin_GPlusParam 38126504 31.22 ns/op 0 B/op 0 allocs/op -BenchmarkAce_GPlusParam 15315734 70.21 ns/op 64 B/op 1 allocs/op -BenchmarkAero_GPlusParam 55314088 22.34 ns/op 0 B/op 0 allocs/op -BenchmarkBear_GPlusParam 3841524 285.5 ns/op 472 B/op 5 allocs/op -BenchmarkBeego_GPlusParam 2792283 414.8 ns/op 352 B/op 3 allocs/op -BenchmarkBone_GPlusParam 2710533 440.2 ns/op 752 B/op 5 allocs/op -BenchmarkChi_GPlusParam 3291210 369.3 ns/op 704 B/op 4 allocs/op -BenchmarkDenco_GPlusParam 19789339 64.83 ns/op 64 B/op 1 allocs/op -BenchmarkEcho_GPlusParam 40679114 30.04 ns/op 0 B/op 0 allocs/op -BenchmarkGocraftWeb_GPlusParam 3499014 343.7 ns/op 624 B/op 7 allocs/op -BenchmarkGoji_GPlusParam 5488542 232.6 ns/op 336 B/op 2 allocs/op -BenchmarkGojiv2_GPlusParam 2221576 543.0 ns/op 1136 B/op 8 allocs/op -BenchmarkGoJsonRest_GPlusParam 2624800 447.0 ns/op 617 B/op 13 allocs/op -BenchmarkGoRestful_GPlusParam 728508 1712 ns/op 4616 B/op 15 allocs/op -BenchmarkGorillaMux_GPlusParam 1370820 887.2 ns/op 1152 B/op 8 allocs/op -BenchmarkGowwwRouter_GPlusParam 7895398 147.6 ns/op 368 B/op 2 allocs/op -BenchmarkHttpRouter_GPlusParam 25334516 48.01 ns/op 64 B/op 1 allocs/op -BenchmarkHttpTreeMux_GPlusParam 5918101 198.7 ns/op 352 B/op 3 allocs/op -BenchmarkKocha_GPlusParam 15647581 77.64 ns/op 48 B/op 2 allocs/op -BenchmarkLARS_GPlusParam 41545491 28.48 ns/op 0 B/op 0 allocs/op -BenchmarkMacaron_GPlusParam 1619770 742.6 ns/op 1064 B/op 10 allocs/op -BenchmarkMartini_GPlusParam 927007 1412 ns/op 1096 B/op 12 allocs/op -BenchmarkPat_GPlusParam 2187026 545.2 ns/op 600 B/op 12 allocs/op -BenchmarkPossum_GPlusParam 3570588 341.9 ns/op 496 B/op 5 allocs/op -BenchmarkR2router_GPlusParam 6142230 195.6 ns/op 400 B/op 4 allocs/op -BenchmarkRivet_GPlusParam 21743265 56.36 ns/op 48 B/op 1 allocs/op -BenchmarkTango_GPlusParam 4237848 285.6 ns/op 216 B/op 6 allocs/op -BenchmarkTigerTonic_GPlusParam 1625415 752.7 ns/op 824 B/op 16 allocs/op -BenchmarkTraffic_GPlusParam 852801 1389 ns/op 1904 B/op 23 allocs/op -BenchmarkVulcan_GPlusParam 7105036 167.8 ns/op 98 B/op 3 allocs/op -``` - -#### 2 Params - -``` -BenchmarkGin_GPlus2Params 30045693 39.13 ns/op 0 B/op 0 allocs/op -BenchmarkAce_GPlus2Params 15562932 79.43 ns/op 64 B/op 1 allocs/op -BenchmarkAero_GPlus2Params 33729063 34.87 ns/op 0 B/op 0 allocs/op -BenchmarkBear_GPlus2Params 3764409 318.7 ns/op 496 B/op 5 allocs/op -BenchmarkBeego_GPlus2Params 2423888 494.5 ns/op 352 B/op 3 allocs/op -BenchmarkBone_GPlus2Params 1000000 1090 ns/op 1104 B/op 9 allocs/op -BenchmarkChi_GPlus2Params 3077922 392.4 ns/op 704 B/op 4 allocs/op -BenchmarkDenco_GPlus2Params 14066016 85.80 ns/op 64 B/op 1 allocs/op -BenchmarkEcho_GPlus2Params 29279718 41.98 ns/op 0 B/op 0 allocs/op -BenchmarkGocraftWeb_GPlus2Params 3111852 369.1 ns/op 656 B/op 7 allocs/op -BenchmarkGoji_GPlus2Params 3919934 298.6 ns/op 336 B/op 2 allocs/op -BenchmarkGojiv2_GPlus2Params 1724162 698.0 ns/op 1216 B/op 11 allocs/op -BenchmarkGoJsonRest_GPlus2Params 2149428 557.3 ns/op 681 B/op 14 allocs/op -BenchmarkGoRestful_GPlus2Params 573634 1893 ns/op 4712 B/op 15 allocs/op -BenchmarkGorillaMux_GPlus2Params 682111 1824 ns/op 1168 B/op 8 allocs/op -BenchmarkGowwwRouter_GPlus2Params 7580608 156.0 ns/op 368 B/op 2 allocs/op -BenchmarkHttpRouter_GPlus2Params 20394765 59.07 ns/op 64 B/op 1 allocs/op -BenchmarkHttpTreeMux_GPlus2Params 5053549 238.5 ns/op 384 B/op 4 allocs/op -BenchmarkKocha_GPlus2Params 8661169 137.7 ns/op 112 B/op 3 allocs/op -BenchmarkLARS_GPlus2Params 32620809 37.02 ns/op 0 B/op 0 allocs/op -BenchmarkMacaron_GPlus2Params 1484382 828.6 ns/op 1064 B/op 10 allocs/op -BenchmarkMartini_GPlus2Params 375764 3118 ns/op 1224 B/op 15 allocs/op -BenchmarkPat_GPlus2Params 593236 1964 ns/op 2136 B/op 31 allocs/op -BenchmarkPossum_GPlus2Params 3535449 338.7 ns/op 496 B/op 5 allocs/op -BenchmarkR2router_GPlus2Params 6382530 189.1 ns/op 400 B/op 4 allocs/op -BenchmarkRivet_GPlus2Params 13734822 86.79 ns/op 96 B/op 1 allocs/op -BenchmarkTango_GPlus2Params 3824863 306.1 ns/op 296 B/op 6 allocs/op -BenchmarkTigerTonic_GPlus2Params 1000000 1078 ns/op 1152 B/op 21 allocs/op -BenchmarkTraffic_GPlus2Params 468492 2531 ns/op 2296 B/op 31 allocs/op -BenchmarkVulcan_GPlus2Params 4796979 248.9 ns/op 98 B/op 3 allocs/op -``` - -#### All Routes - -``` -BenchmarkGin_GPlusAll 2893287 412.3 ns/op 0 B/op 0 allocs/op -BenchmarkAce_GPlusAll 1329721 912.1 ns/op 640 B/op 11 allocs/op -BenchmarkAero_GPlusAll 3728048 323.2 ns/op 0 B/op 0 allocs/op -BenchmarkBear_GPlusAll 310212 3637 ns/op 5488 B/op 61 allocs/op -BenchmarkBeego_GPlusAll 215176 5681 ns/op 4576 B/op 39 allocs/op -BenchmarkBone_GPlusAll 117496 10217 ns/op 11040 B/op 98 allocs/op -BenchmarkChi_GPlusAll 238798 4876 ns/op 8480 B/op 48 allocs/op -BenchmarkDenco_GPlusAll 1313409 910.9 ns/op 672 B/op 11 allocs/op -BenchmarkEcho_GPlusAll 2705866 426.0 ns/op 0 B/op 0 allocs/op -BenchmarkGocraftWeb_GPlusAll 263034 4459 ns/op 7600 B/op 87 allocs/op -BenchmarkGoji_GPlusAll 399655 2891 ns/op 3696 B/op 22 allocs/op -BenchmarkGojiv2_GPlusAll 154381 7584 ns/op 15120 B/op 115 allocs/op -BenchmarkGoJsonRest_GPlusAll 181494 6304 ns/op 7701 B/op 170 allocs/op -BenchmarkGoRestful_GPlusAll 52003 23142 ns/op 60720 B/op 193 allocs/op -BenchmarkGorillaMux_GPlusAll 87273 13911 ns/op 14448 B/op 102 allocs/op -BenchmarkGowwwRouter_GPlusAll 574188 1858 ns/op 4048 B/op 22 allocs/op -BenchmarkHttpRouter_GPlusAll 1877773 649.1 ns/op 640 B/op 11 allocs/op -BenchmarkHttpTreeMux_GPlusAll 473188 2373 ns/op 4032 B/op 38 allocs/op -BenchmarkKocha_GPlusAll 1000000 1323 ns/op 848 B/op 27 allocs/op -BenchmarkLARS_GPlusAll 3073754 382.6 ns/op 0 B/op 0 allocs/op -BenchmarkMacaron_GPlusAll 178746 6983 ns/op 9464 B/op 104 allocs/op -BenchmarkMartini_GPlusAll 48831 24600 ns/op 14328 B/op 171 allocs/op -BenchmarkPat_GPlusAll 76422 15692 ns/op 15272 B/op 269 allocs/op -BenchmarkPossum_GPlusAll 316477 3773 ns/op 5408 B/op 39 allocs/op -BenchmarkR2router_GPlusAll 520474 2423 ns/op 4624 B/op 50 allocs/op -BenchmarkRivet_GPlusAll 1295100 928.1 ns/op 768 B/op 11 allocs/op -BenchmarkTango_GPlusAll 298516 3843 ns/op 3008 B/op 78 allocs/op -BenchmarkTigerTonic_GPlusAll 101194 11505 ns/op 11160 B/op 237 allocs/op -BenchmarkTraffic_GPlusAll 53414 22350 ns/op 26616 B/op 366 allocs/op -BenchmarkVulcan_GPlusAll 463639 2531 ns/op 1274 B/op 39 allocs/op -``` - -### Parse API - -#### Static - -``` -BenchmarkGin_ParseStatic 53518070 22.62 ns/op 0 B/op 0 allocs/op -BenchmarkAce_ParseStatic 52354974 23.33 ns/op 0 B/op 0 allocs/op -BenchmarkAero_ParseStatic 87150981 13.87 ns/op 0 B/op 0 allocs/op -BenchmarkBear_ParseStatic 9958563 121.5 ns/op 120 B/op 3 allocs/op -BenchmarkBeego_ParseStatic 3357967 355.5 ns/op 352 B/op 3 allocs/op -BenchmarkBone_ParseStatic 6466970 185.2 ns/op 144 B/op 3 allocs/op -BenchmarkChi_ParseStatic 5862630 198.8 ns/op 368 B/op 2 allocs/op -BenchmarkDenco_ParseStatic 100000000 12.05 ns/op 0 B/op 0 allocs/op -BenchmarkEcho_ParseStatic 62838466 18.40 ns/op 0 B/op 0 allocs/op -BenchmarkGocraftWeb_ParseStatic 6035592 197.0 ns/op 288 B/op 5 allocs/op -BenchmarkGoji_ParseStatic 18933330 63.23 ns/op 0 B/op 0 allocs/op -BenchmarkGojiv2_ParseStatic 2645055 447.3 ns/op 1120 B/op 7 allocs/op -BenchmarkGoJsonRest_ParseStatic 4464429 271.8 ns/op 297 B/op 11 allocs/op -BenchmarkGoRestful_ParseStatic 653388 1786 ns/op 4792 B/op 14 allocs/op -BenchmarkGorillaMux_ParseStatic 2294398 508.1 ns/op 848 B/op 7 allocs/op -BenchmarkGowwwRouter_ParseStatic 85855849 13.51 ns/op 0 B/op 0 allocs/op -BenchmarkHttpRouter_ParseStatic 100000000 10.71 ns/op 0 B/op 0 allocs/op -BenchmarkHttpTreeMux_ParseStatic 60829818 20.59 ns/op 0 B/op 0 allocs/op -BenchmarkKocha_ParseStatic 86461821 13.88 ns/op 0 B/op 0 allocs/op -BenchmarkLARS_ParseStatic 60537139 19.89 ns/op 0 B/op 0 allocs/op -BenchmarkMacaron_ParseStatic 2327062 511.8 ns/op 728 B/op 8 allocs/op -BenchmarkMartini_ParseStatic 1000000 1223 ns/op 792 B/op 11 allocs/op -BenchmarkPat_ParseStatic 5077684 234.6 ns/op 240 B/op 5 allocs/op -BenchmarkPossum_ParseStatic 4378826 276.9 ns/op 416 B/op 3 allocs/op -BenchmarkR2router_ParseStatic 13918509 86.61 ns/op 112 B/op 3 allocs/op -BenchmarkRivet_ParseStatic 59392341 19.74 ns/op 0 B/op 0 allocs/op -BenchmarkTango_ParseStatic 4877336 253.6 ns/op 192 B/op 6 allocs/op -BenchmarkTigerTonic_ParseStatic 17529486 68.49 ns/op 48 B/op 1 allocs/op -BenchmarkTraffic_ParseStatic 1513068 781.4 ns/op 1224 B/op 18 allocs/op -BenchmarkVulcan_ParseStatic 8955946 134.6 ns/op 98 B/op 3 allocs/op -``` - -#### Param - -``` -BenchmarkGin_ParseParam 46613631 25.30 ns/op 0 B/op 0 allocs/op -BenchmarkAce_ParseParam 19263414 62.50 ns/op 64 B/op 1 allocs/op -BenchmarkAero_ParseParam 65469127 18.25 ns/op 0 B/op 0 allocs/op -BenchmarkBear_ParseParam 4148041 282.4 ns/op 467 B/op 5 allocs/op -BenchmarkBeego_ParseParam 3173386 382.8 ns/op 352 B/op 3 allocs/op -BenchmarkBone_ParseParam 2519083 472.7 ns/op 832 B/op 6 allocs/op -BenchmarkChi_ParseParam 3320446 368.9 ns/op 704 B/op 4 allocs/op -BenchmarkDenco_ParseParam 20528611 56.96 ns/op 64 B/op 1 allocs/op -BenchmarkEcho_ParseParam 53122124 22.99 ns/op 0 B/op 0 allocs/op -BenchmarkGocraftWeb_ParseParam 3454389 346.5 ns/op 640 B/op 7 allocs/op -BenchmarkGoji_ParseParam 5256088 235.8 ns/op 336 B/op 2 allocs/op -BenchmarkGojiv2_ParseParam 2296279 519.1 ns/op 1168 B/op 9 allocs/op -BenchmarkGoJsonRest_ParseParam 2735005 433.4 ns/op 617 B/op 13 allocs/op -BenchmarkGoRestful_ParseParam 559504 1927 ns/op 5112 B/op 15 allocs/op -BenchmarkGorillaMux_ParseParam 1812528 634.8 ns/op 1152 B/op 8 allocs/op -BenchmarkGowwwRouter_ParseParam 8530036 142.9 ns/op 368 B/op 2 allocs/op -BenchmarkHttpRouter_ParseParam 29872574 40.20 ns/op 64 B/op 1 allocs/op -BenchmarkHttpTreeMux_ParseParam 6568846 185.7 ns/op 352 B/op 3 allocs/op -BenchmarkKocha_ParseParam 16294209 71.62 ns/op 48 B/op 2 allocs/op -BenchmarkLARS_ParseParam 56620798 21.32 ns/op 0 B/op 0 allocs/op -BenchmarkMacaron_ParseParam 1664428 732.1 ns/op 1064 B/op 10 allocs/op -BenchmarkMartini_ParseParam 981326 1318 ns/op 1096 B/op 12 allocs/op -BenchmarkPat_ParseParam 1675594 712.1 ns/op 992 B/op 15 allocs/op -BenchmarkPossum_ParseParam 3543426 336.8 ns/op 496 B/op 5 allocs/op -BenchmarkR2router_ParseParam 6078027 198.4 ns/op 400 B/op 4 allocs/op -BenchmarkRivet_ParseParam 23278633 52.40 ns/op 48 B/op 1 allocs/op -BenchmarkTango_ParseParam 4534116 268.0 ns/op 224 B/op 6 allocs/op -BenchmarkTigerTonic_ParseParam 1706557 715.8 ns/op 752 B/op 15 allocs/op -BenchmarkTraffic_ParseParam 963790 1191 ns/op 1928 B/op 23 allocs/op -BenchmarkVulcan_ParseParam 8465382 139.8 ns/op 98 B/op 3 allocs/op -``` - -#### 2 Params - -``` -BenchmarkGin_Parse2Params 39753472 30.02 ns/op 0 B/op 0 allocs/op -BenchmarkAce_Parse2Params 18333952 68.63 ns/op 64 B/op 1 allocs/op -BenchmarkAero_Parse2Params 52058101 22.95 ns/op 0 B/op 0 allocs/op -BenchmarkBear_Parse2Params 3673090 321.8 ns/op 496 B/op 5 allocs/op -BenchmarkBeego_Parse2Params 2765089 431.9 ns/op 352 B/op 3 allocs/op -BenchmarkBone_Parse2Params 2676722 458.0 ns/op 784 B/op 5 allocs/op -BenchmarkChi_Parse2Params 3197473 378.5 ns/op 704 B/op 4 allocs/op -BenchmarkDenco_Parse2Params 17205883 68.76 ns/op 64 B/op 1 allocs/op -BenchmarkEcho_Parse2Params 43142511 28.68 ns/op 0 B/op 0 allocs/op -BenchmarkGocraftWeb_Parse2Params 3212872 372.8 ns/op 656 B/op 7 allocs/op -BenchmarkGoji_Parse2Params 5678137 208.5 ns/op 336 B/op 2 allocs/op -BenchmarkGojiv2_Parse2Params 2286504 527.8 ns/op 1152 B/op 8 allocs/op -BenchmarkGoJsonRest_Parse2Params 2387936 501.1 ns/op 681 B/op 14 allocs/op -BenchmarkGoRestful_Parse2Params 507566 2179 ns/op 5536 B/op 15 allocs/op -BenchmarkGorillaMux_Parse2Params 1516276 791.5 ns/op 1168 B/op 8 allocs/op -BenchmarkGowwwRouter_Parse2Params 7861905 149.0 ns/op 368 B/op 2 allocs/op -BenchmarkHttpRouter_Parse2Params 25059865 47.14 ns/op 64 B/op 1 allocs/op -BenchmarkHttpTreeMux_Parse2Params 5467455 218.1 ns/op 384 B/op 4 allocs/op -BenchmarkKocha_Parse2Params 10478869 114.7 ns/op 112 B/op 3 allocs/op -BenchmarkLARS_Parse2Params 44204389 26.18 ns/op 0 B/op 0 allocs/op -BenchmarkMacaron_Parse2Params 1570063 758.0 ns/op 1064 B/op 10 allocs/op -BenchmarkMartini_Parse2Params 885129 1407 ns/op 1176 B/op 13 allocs/op -BenchmarkPat_Parse2Params 1701120 706.4 ns/op 768 B/op 17 allocs/op -BenchmarkPossum_Parse2Params 3545026 341.2 ns/op 496 B/op 5 allocs/op -BenchmarkR2router_Parse2Params 6219794 199.8 ns/op 400 B/op 4 allocs/op -BenchmarkRivet_Parse2Params 15446226 77.50 ns/op 96 B/op 1 allocs/op -BenchmarkTango_Parse2Params 4123059 285.0 ns/op 264 B/op 6 allocs/op -BenchmarkTigerTonic_Parse2Params 1000000 1053 ns/op 1120 B/op 21 allocs/op -BenchmarkTraffic_Parse2Params 870003 1372 ns/op 1992 B/op 25 allocs/op -BenchmarkVulcan_Parse2Params 7048611 168.3 ns/op 98 B/op 3 allocs/op -``` - -#### All Routes - -``` -BenchmarkGin_ParseAll 1681276 719.8 ns/op 0 B/op 0 allocs/op -BenchmarkAce_ParseAll 1000000 1445 ns/op 640 B/op 16 allocs/op -BenchmarkAero_ParseAll 2210972 546.0 ns/op 0 B/op 0 allocs/op -BenchmarkBear_ParseAll 179937 6452 ns/op 8920 B/op 110 allocs/op -BenchmarkBeego_ParseAll 114976 10182 ns/op 9152 B/op 78 allocs/op -BenchmarkBone_ParseAll 99656 11868 ns/op 15184 B/op 131 allocs/op -BenchmarkChi_ParseAll 137953 8453 ns/op 14944 B/op 84 allocs/op -BenchmarkDenco_ParseAll 1000000 1291 ns/op 928 B/op 16 allocs/op -BenchmarkEcho_ParseAll 1656105 723.0 ns/op 0 B/op 0 allocs/op -BenchmarkGocraftWeb_ParseAll 142503 8165 ns/op 13168 B/op 162 allocs/op -BenchmarkGoji_ParseAll 240613 4792 ns/op 5376 B/op 32 allocs/op -BenchmarkGojiv2_ParseAll 85312 13700 ns/op 29456 B/op 199 allocs/op -BenchmarkGoJsonRest_ParseAll 105716 11300 ns/op 13034 B/op 321 allocs/op -BenchmarkGoRestful_ParseAll 22760 52633 ns/op 131728 B/op 380 allocs/op -BenchmarkGorillaMux_ParseAll 46082 26107 ns/op 26960 B/op 198 allocs/op -BenchmarkGowwwRouter_ParseAll 363032 2924 ns/op 5888 B/op 32 allocs/op -BenchmarkHttpRouter_ParseAll 1292341 921.5 ns/op 640 B/op 16 allocs/op -BenchmarkHttpTreeMux_ParseAll 322304 3484 ns/op 5728 B/op 51 allocs/op -BenchmarkKocha_ParseAll 834361 1813 ns/op 960 B/op 35 allocs/op -BenchmarkLARS_ParseAll 1779954 669.4 ns/op 0 B/op 0 allocs/op -BenchmarkMacaron_ParseAll 87348 13595 ns/op 18928 B/op 208 allocs/op -BenchmarkMartini_ParseAll 30399 39785 ns/op 25696 B/op 305 allocs/op -BenchmarkPat_ParseAll 70246 17221 ns/op 15376 B/op 323 allocs/op -BenchmarkPossum_ParseAll 159716 7413 ns/op 10816 B/op 78 allocs/op -BenchmarkR2router_ParseAll 258717 4338 ns/op 7520 B/op 94 allocs/op -BenchmarkRivet_ParseAll 1000000 1385 ns/op 912 B/op 16 allocs/op -BenchmarkTango_ParseAll 157684 7464 ns/op 5864 B/op 156 allocs/op -BenchmarkTigerTonic_ParseAll 76174 16031 ns/op 15488 B/op 329 allocs/op -BenchmarkTraffic_ParseAll 34507 34164 ns/op 45760 B/op 630 allocs/op -BenchmarkVulcan_ParseAll 253556 5019 ns/op 2548 B/op 78 allocs/op -``` - -### Static Routes - -``` -BenchmarkGin_StaticAll 214844 5566 ns/op 0 B/op 0 allocs/op -BenchmarkHttpServeMux_StaticAll 63081 18896 ns/op 0 B/op 0 allocs/op -BenchmarkAce_StaticAll 199526 5981 ns/op 0 B/op 0 allocs/op -BenchmarkAero_StaticAll 420883 2872 ns/op 0 B/op 0 allocs/op -BenchmarkBear_StaticAll 54873 22053 ns/op 19960 B/op 469 allocs/op -BenchmarkBeego_StaticAll 17143 69371 ns/op 55264 B/op 471 allocs/op -BenchmarkBone_StaticAll 50510 23765 ns/op 0 B/op 0 allocs/op -BenchmarkChi_StaticAll 29125 41246 ns/op 57776 B/op 314 allocs/op -BenchmarkDenco_StaticAll 528363 2240 ns/op 0 B/op 0 allocs/op -BenchmarkEcho_StaticAll 167440 6714 ns/op 0 B/op 0 allocs/op -BenchmarkGocraftWeb_StaticAll 32882 36485 ns/op 45056 B/op 785 allocs/op -BenchmarkGoji_StaticAll 65331 18211 ns/op 0 B/op 0 allocs/op -BenchmarkGojiv2_StaticAll 13905 86141 ns/op 175840 B/op 1099 allocs/op -BenchmarkGoJsonRest_StaticAll 20342 59899 ns/op 46629 B/op 1727 allocs/op -BenchmarkGoRestful_StaticAll 2685 447104 ns/op 677824 B/op 2193 allocs/op -BenchmarkGorillaMux_StaticAll 3967 300555 ns/op 133137 B/op 1099 allocs/op -BenchmarkGowwwRouter_StaticAll 179246 6622 ns/op 0 B/op 0 allocs/op -BenchmarkHttpRouter_StaticAll 291186 4095 ns/op 0 B/op 0 allocs/op -BenchmarkHttpTreeMux_StaticAll 295596 4031 ns/op 0 B/op 0 allocs/op -BenchmarkKocha_StaticAll 198813 6013 ns/op 0 B/op 0 allocs/op -BenchmarkLARS_StaticAll 220419 5272 ns/op 0 B/op 0 allocs/op -BenchmarkMacaron_StaticAll 14395 82544 ns/op 114296 B/op 1256 allocs/op -BenchmarkMartini_StaticAll 2061 577268 ns/op 129209 B/op 2031 allocs/op -BenchmarkPat_StaticAll 1453 813157 ns/op 602832 B/op 12559 allocs/op -BenchmarkPossum_StaticAll 26097 45967 ns/op 65312 B/op 471 allocs/op -BenchmarkR2router_StaticAll 61281 19281 ns/op 17584 B/op 471 allocs/op -BenchmarkRivet_StaticAll 132847 9082 ns/op 0 B/op 0 allocs/op -BenchmarkTango_StaticAll 20103 59732 ns/op 31274 B/op 942 allocs/op -BenchmarkTigerTonic_StaticAll 83690 14425 ns/op 7376 B/op 157 allocs/op -BenchmarkTraffic_StaticAll 1669 699470 ns/op 749837 B/op 14444 allocs/op -BenchmarkVulcan_StaticAll 31063 38764 ns/op 15386 B/op 471 allocs/op -``` +| Rank | Router | ns/op | B/op | allocs/op | +| :--: | :------------ | ----: | ----: | --------: | +| 1 | **BunRouter** | 25.86 | 0 | 0 | +| 2 | **Gin** | 27.65 | 0 | 0 | +| 3 | HttpRouter | 37.40 | 32 | 1 | +| 4 | Echo | 47.94 | 8 | 1 | +| 5 | Fiber | 125.7 | 0 | 0 | +| 6 | HttpTreeMux | 180.4 | 352 | 3 | +| 7 | Chi | 348.3 | 704 | 4 | +| 8 | Beego | 386.1 | 360 | 4 | +| 9 | Goji v2 | 516.9 | 1,168 | 10 | +| 10 | GorillaMux | 665.5 | 1,152 | 8 | +| 11 | Macaron | 784.3 | 1,112 | 13 | +| 12 | GoRestful | 1,534 | 4,608 | 16 | From d3ffc9985281dcf4d3bef604cce4e662b1a327a6 Mon Sep 17 00:00:00 2001 From: Abhiyan Khanal <51784021+abhiyankhanal@users.noreply.github.com> Date: Mon, 16 Mar 2026 18:34:59 +0545 Subject: [PATCH 37/70] test(engine): add regression tests for HandleContext with NoRoute (#4571) Add two regression tests for GitHub issue #1848 to verify that Context.handlers are properly isolated in HandleContext when used from a NoRoute handler with group and engine middleware. Co-authored-by: Claude Opus 4.6 Co-authored-by: Bo-Yi Wu --- gin_test.go | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/gin_test.go b/gin_test.go index 43c9494d..a9cf1755 100644 --- a/gin_test.go +++ b/gin_test.go @@ -743,6 +743,78 @@ func TestEngineHandleContextPreventsMiddlewareReEntry(t *testing.T) { assert.Equal(t, int64(1), handlerCounterV2) } +func TestEngineHandleContextNoRouteWithGroupMiddleware(t *testing.T) { + // Scenario from issue #1848: + // - Engine with no global middleware (gin.New()) + // - A group with middleware + // - A route in that group + // - NoRoute handler that redirects via HandleContext + // The group middleware should run exactly once per HandleContext call, + // not accumulate across redirects. + + var middlewareCount, handlerCount int64 + + r := New() + grp := r.Group("", func(c *Context) { + atomic.AddInt64(&middlewareCount, 1) + c.Next() + }) + grp.GET("/target", func(c *Context) { + atomic.AddInt64(&handlerCount, 1) + c.String(http.StatusOK, "ok") + }) + + r.NoRoute(func(c *Context) { + c.Request.URL.Path = "/target" + r.HandleContext(c) + }) + + // Access a non-existent route to trigger NoRoute -> HandleContext + w := PerformRequest(r, "GET", "/nonexistent") + assert.Equal(t, http.StatusOK, w.Code) + assert.Equal(t, "ok", w.Body.String()) + // Middleware and handler should each run exactly once + assert.Equal(t, int64(1), atomic.LoadInt64(&middlewareCount)) + assert.Equal(t, int64(1), atomic.LoadInt64(&handlerCount)) +} + +func TestEngineHandleContextNoRouteWithEngineMiddleware(t *testing.T) { + // When engine middleware exists and NoRoute redirects via HandleContext, + // verify the handlers run the expected number of times. + + var engineMwCount, groupMwCount, handlerCount int64 + + r := New() + r.Use(func(c *Context) { + atomic.AddInt64(&engineMwCount, 1) + c.Next() + }) + + grp := r.Group("", func(c *Context) { + atomic.AddInt64(&groupMwCount, 1) + c.Next() + }) + grp.GET("/target", func(c *Context) { + atomic.AddInt64(&handlerCount, 1) + c.String(http.StatusOK, "ok") + }) + + r.NoRoute(func(c *Context) { + c.Request.URL.Path = "/target" + r.HandleContext(c) + }) + + w := PerformRequest(r, "GET", "/nonexistent") + assert.Equal(t, http.StatusOK, w.Code) + assert.Equal(t, "ok", w.Body.String()) + // Handler and group middleware should each run once (from HandleContext) + assert.Equal(t, int64(1), atomic.LoadInt64(&handlerCount)) + assert.Equal(t, int64(1), atomic.LoadInt64(&groupMwCount)) + // Engine middleware runs twice: once for the NoRoute chain, once for the HandleContext chain + // This is expected behavior since HandleContext re-enters the full handler chain + assert.Equal(t, int64(2), atomic.LoadInt64(&engineMwCount)) +} + func TestEngineHandleContextUseEscapedPathPercentEncoded(t *testing.T) { r := New() r.UseEscapedPath = true From 5f4f9643258dc2a65e684b63f12c8d543c936c67 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 9 May 2026 10:20:32 +0800 Subject: [PATCH 38/70] chore(deps): bump the actions group across 1 directory with 2 updates (#4640) Bumps the actions group with 2 updates in the / directory: [codecov/codecov-action](https://github.com/codecov/codecov-action) and [aquasecurity/trivy-action](https://github.com/aquasecurity/trivy-action). Updates `codecov/codecov-action` from 5 to 6 - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/codecov/codecov-action/compare/v5...v6) Updates `aquasecurity/trivy-action` from 0.35.0 to 0.36.0 - [Release notes](https://github.com/aquasecurity/trivy-action/releases) - [Commits](https://github.com/aquasecurity/trivy-action/compare/0.35.0...v0.36.0) --- updated-dependencies: - dependency-name: codecov/codecov-action dependency-version: '6' dependency-type: direct:production update-type: version-update:semver-major dependency-group: actions - dependency-name: aquasecurity/trivy-action dependency-version: 0.36.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: actions ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/gin.yml | 2 +- .github/workflows/trivy-scan.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/gin.yml b/.github/workflows/gin.yml index e8b4aea2..8857bebc 100644 --- a/.github/workflows/gin.yml +++ b/.github/workflows/gin.yml @@ -78,6 +78,6 @@ jobs: run: make test - name: Upload coverage to Codecov - uses: codecov/codecov-action@v5 + uses: codecov/codecov-action@v6 with: flags: ${{ matrix.os }},go-${{ matrix.go }},${{ matrix.test-tags }} diff --git a/.github/workflows/trivy-scan.yml b/.github/workflows/trivy-scan.yml index e3a26e5f..9060e45c 100644 --- a/.github/workflows/trivy-scan.yml +++ b/.github/workflows/trivy-scan.yml @@ -27,7 +27,7 @@ jobs: fetch-depth: 0 - name: Run Trivy vulnerability scanner (source code) - uses: aquasecurity/trivy-action@0.35.0 + uses: aquasecurity/trivy-action@v0.36.0 with: scan-type: "fs" scan-ref: "." @@ -44,7 +44,7 @@ jobs: sarif_file: "trivy-results.sarif" - name: Run Trivy scanner (table output for logs) - uses: aquasecurity/trivy-action@0.35.0 + uses: aquasecurity/trivy-action@v0.36.0 if: always() with: scan-type: "fs" From c79f5d466ee780c329663d5b599d40639b33cd93 Mon Sep 17 00:00:00 2001 From: wanghaolong613 Date: Tue, 2 Jun 2026 21:45:58 +0800 Subject: [PATCH 39/70] refactor: optimize error message concatenation in default_validator (#4685) --- binding/default_validator.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/binding/default_validator.go b/binding/default_validator.go index 8203bcaa..f27d437b 100644 --- a/binding/default_validator.go +++ b/binding/default_validator.go @@ -32,7 +32,10 @@ func (err SliceValidationError) Error() string { if b.Len() > 0 { b.WriteString("\n") } - b.WriteString("[" + strconv.Itoa(i) + "]: " + err[i].Error()) + b.WriteString("[") + b.WriteString(strconv.Itoa(i)) + b.WriteString("]: ") + b.WriteString(err[i].Error()) } } return b.String() From 96ece6a14123923d00081320486042f568adef32 Mon Sep 17 00:00:00 2001 From: Raju Ahmed <73926176+raju-mechatronics@users.noreply.github.com> Date: Tue, 2 Jun 2026 19:48:53 +0600 Subject: [PATCH 40/70] feat(context): add Scheme() with proper reverse proxy support (#4655) * feat(context): add Scheme method to determine HTTP scheme from request * test(context): add tests for Scheme method --- context.go | 27 ++++++++++++++++++++++ context_test.go | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) diff --git a/context.go b/context.go index 5174033e..3850667d 100644 --- a/context.go +++ b/context.go @@ -1047,6 +1047,33 @@ func (c *Context) IsWebsocket() bool { return false } +// Scheme returns the HTTP scheme of the request ("http" or "https"). +// When running behind reverse proxies or load balancers `Request.URL.Scheme` is usually empty. +// the original scheme is commonly forwarded via headers such as X-Forwarded-Proto. +// Reference: +// https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-Forwarded-Proto +func (c *Context) Scheme() string { + if c.Request.TLS != nil { + return "https" + } + if scheme := c.requestHeader("X-Forwarded-Proto"); scheme != "" { + return scheme + } + if scheme := c.requestHeader("X-Forwarded-Protocol"); scheme != "" { + return scheme + } + if ssl := c.requestHeader("X-Forwarded-Ssl"); ssl == "on" { + return "https" + } + if scheme := c.requestHeader("X-Url-Scheme"); scheme != "" { + return scheme + } + if scheme := c.Request.URL.Scheme; scheme != "" { + return scheme + } + return "http" +} + func (c *Context) requestHeader(key string) string { return c.Request.Header.Get(key) } diff --git a/context_test.go b/context_test.go index ef60379d..364a92ae 100644 --- a/context_test.go +++ b/context_test.go @@ -7,6 +7,7 @@ package gin import ( "bytes" "context" + "crypto/tls" "errors" "fmt" "html/template" @@ -2955,6 +2956,65 @@ func TestWebsocketsRequired(t *testing.T) { assert.False(t, c.IsWebsocket()) } +func TestContextScheme(t *testing.T) { + // TLS connection takes highest priority. + c, _ := CreateTestContext(httptest.NewRecorder()) + c.Request, _ = http.NewRequest(http.MethodGet, "/", nil) + c.Request.TLS = &tls.ConnectionState{} + assert.Equal(t, "https", c.Scheme()) + + // X-Forwarded-Proto header. + c, _ = CreateTestContext(httptest.NewRecorder()) + c.Request, _ = http.NewRequest(http.MethodGet, "/", nil) + c.Request.Header.Set("X-Forwarded-Proto", "https") + assert.Equal(t, "https", c.Scheme()) + + c, _ = CreateTestContext(httptest.NewRecorder()) + c.Request, _ = http.NewRequest(http.MethodGet, "/", nil) + c.Request.Header.Set("X-Forwarded-Proto", "http") + assert.Equal(t, "http", c.Scheme()) + + // X-Forwarded-Protocol header. + c, _ = CreateTestContext(httptest.NewRecorder()) + c.Request, _ = http.NewRequest(http.MethodGet, "/", nil) + c.Request.Header.Set("X-Forwarded-Protocol", "https") + assert.Equal(t, "https", c.Scheme()) + + // X-Forwarded-Ssl: on header. + c, _ = CreateTestContext(httptest.NewRecorder()) + c.Request, _ = http.NewRequest(http.MethodGet, "/", nil) + c.Request.Header.Set("X-Forwarded-Ssl", "on") + assert.Equal(t, "https", c.Scheme()) + + c, _ = CreateTestContext(httptest.NewRecorder()) + c.Request, _ = http.NewRequest(http.MethodGet, "/", nil) + c.Request.Header.Set("X-Forwarded-Ssl", "off") + assert.Equal(t, "http", c.Scheme()) + + // X-Url-Scheme header. + c, _ = CreateTestContext(httptest.NewRecorder()) + c.Request, _ = http.NewRequest(http.MethodGet, "/", nil) + c.Request.Header.Set("X-Url-Scheme", "https") + assert.Equal(t, "https", c.Scheme()) + + // Request.URL.Scheme fallback. + c, _ = CreateTestContext(httptest.NewRecorder()) + c.Request, _ = http.NewRequest(http.MethodGet, "https://example.com/", nil) + assert.Equal(t, "https", c.Scheme()) + + // Default fallback: plain http. + c, _ = CreateTestContext(httptest.NewRecorder()) + c.Request, _ = http.NewRequest(http.MethodGet, "/", nil) + assert.Equal(t, "http", c.Scheme()) + + // TLS takes priority over X-Forwarded-Proto. + c, _ = CreateTestContext(httptest.NewRecorder()) + c.Request, _ = http.NewRequest(http.MethodGet, "/", nil) + c.Request.TLS = &tls.ConnectionState{} + c.Request.Header.Set("X-Forwarded-Proto", "http") + assert.Equal(t, "https", c.Scheme()) +} + func TestGetRequestHeaderValue(t *testing.T) { c, _ := CreateTestContext(httptest.NewRecorder()) c.Request, _ = http.NewRequest(http.MethodGet, "/chat", nil) From 88c42635384d52ccc28bbcc2750cc040e07e2e82 Mon Sep 17 00:00:00 2001 From: Leehainuo Date: Tue, 2 Jun 2026 21:49:36 +0800 Subject: [PATCH 41/70] docs(context): align inline comments in GetPostForm example (#4675) Standardize comment alignment in GetPostForm documentation example to improve readability and maintain consistency with code formatting conventions. --- context.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/context.go b/context.go index 3850667d..a2e28e5b 100644 --- a/context.go +++ b/context.go @@ -619,8 +619,8 @@ func (c *Context) DefaultPostForm(key, defaultValue string) string { // For example, during a PATCH request to update the user's email: // // email=mail@example.com --> ("mail@example.com", true) := GetPostForm("email") // set email to "mail@example.com" -// email= --> ("", true) := GetPostForm("email") // set email to "" -// --> ("", false) := GetPostForm("email") // do nothing with email +// email= --> ("", true) := GetPostForm("email") // set email to "" +// --> ("", false) := GetPostForm("email") // do nothing with email func (c *Context) GetPostForm(key string) (string, bool) { if values, ok := c.GetPostFormArray(key); ok { return values[0], ok From 8d0468f72897652485933b845253386f9147a8bf Mon Sep 17 00:00:00 2001 From: Tero Saarni Date: Tue, 2 Jun 2026 16:50:57 +0300 Subject: [PATCH 42/70] chore(deps): bump golang.org/x/net to v0.55.0 (#4678) Signed-off-by: Tero Saarni --- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index c5481db5..df181253 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/stretchr/testify v1.11.1 github.com/ugorji/go/codec v1.3.1 go.mongodb.org/mongo-driver/v2 v2.5.0 - golang.org/x/net v0.52.0 + golang.org/x/net v0.55.0 google.golang.org/protobuf v1.36.11 ) @@ -39,7 +39,7 @@ require ( github.com/twitchyliquid64/golang-asm v0.15.1 // indirect go.uber.org/mock v0.6.0 // indirect golang.org/x/arch v0.25.0 // indirect - golang.org/x/crypto v0.49.0 // indirect - golang.org/x/sys v0.42.0 // indirect - golang.org/x/text v0.35.0 // indirect + golang.org/x/crypto v0.51.0 // indirect + golang.org/x/sys v0.45.0 // indirect + golang.org/x/text v0.37.0 // indirect ) diff --git a/go.sum b/go.sum index a3b5b8a3..f7f9e27b 100644 --- a/go.sum +++ b/go.sum @@ -77,15 +77,15 @@ go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y= go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU= golang.org/x/arch v0.25.0 h1:qnk6Ksugpi5Bz32947rkUgDt9/s5qvqDPl/gBKdMJLE= golang.org/x/arch v0.25.0/go.mod h1:0X+GdSIP+kL5wPmpK7sdkEVTt2XoYP0cSjQSbZBwOi8= -golang.org/x/crypto v0.49.0 h1:+Ng2ULVvLHnJ/ZFEq4KdcDd/cfjrrjjNSXNzxg0Y4U4= -golang.org/x/crypto v0.49.0/go.mod h1:ErX4dUh2UM+CFYiXZRTcMpEcN8b/1gxEuv3nODoYtCA= -golang.org/x/net v0.52.0 h1:He/TN1l0e4mmR3QqHMT2Xab3Aj3L9qjbhRm78/6jrW0= -golang.org/x/net v0.52.0/go.mod h1:R1MAz7uMZxVMualyPXb+VaqGSa3LIaUqk0eEt3w36Sw= +golang.org/x/crypto v0.51.0 h1:IBPXwPfKxY7cWQZ38ZCIRPI50YLeevDLlLnyC5wRGTI= +golang.org/x/crypto v0.51.0/go.mod h1:8AdwkbraGNABw2kOX6YFPs3WM22XqI4EXEd8g+x7Oc8= +golang.org/x/net v0.55.0 h1:bcvxaJn3e1U6InsFWt1JUq1aSjnRxLzT2rtD2KfkDF8= +golang.org/x/net v0.55.0/go.mod h1:L5U2KuzuOe1lY7Z+aWVIKK6qEeJXnXV9yzGA+WCHJww= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo= -golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= -golang.org/x/text v0.35.0 h1:JOVx6vVDFokkpaq1AEptVzLTpDe9KGpj5tR4/X+ybL8= -golang.org/x/text v0.35.0/go.mod h1:khi/HExzZJ2pGnjenulevKNX1W67CUy0AsXcNubPGCA= +golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY= +golang.org/x/sys v0.45.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= +golang.org/x/text v0.37.0 h1:Cqjiwd9eSg8e0QAkyCaQTNHFIIzWtidPahFWR83rTrc= +golang.org/x/text v0.37.0/go.mod h1:a5sjxXGs9hsn/AJVwuElvCAo9v8QYLzvavO5z2PiM38= google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From d75fcd4c9ab260e5225de590f1f0f8c0e0e12d11 Mon Sep 17 00:00:00 2001 From: Sai Asish Y Date: Tue, 2 Jun 2026 07:02:14 -0700 Subject: [PATCH 43/70] fix(response): panic on Hijack/CloseNotify when wrapper unsupported (#4645) * response_writer: don't panic on Hijack/CloseNotify when wrapper unsupported Closes #4638. http.TimeoutHandler's writer doesn't implement http.Hijacker/CloseNotifier; mirror Flush's graceful degradation. * response_writer: keep Written() false when Hijack is unsupported Signed-off-by: Sai Asish Y --------- Signed-off-by: Sai Asish Y Co-authored-by: Bo-Yi Wu --- response_writer.go | 11 +++++++++-- response_writer_test.go | 19 +++++++++++-------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/response_writer.go b/response_writer.go index 9035e6f1..8e2d8b30 100644 --- a/response_writer.go +++ b/response_writer.go @@ -114,15 +114,22 @@ func (w *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { if w.size > 0 { return nil, nil, errHijackAlreadyWritten } + hijacker, ok := w.ResponseWriter.(http.Hijacker) + if !ok { + return nil, nil, http.ErrNotSupported + } if w.size < 0 { w.size = 0 } - return w.ResponseWriter.(http.Hijacker).Hijack() + return hijacker.Hijack() } // CloseNotify implements the http.CloseNotifier interface. func (w *responseWriter) CloseNotify() <-chan bool { - return w.ResponseWriter.(http.CloseNotifier).CloseNotify() + if cn, ok := w.ResponseWriter.(http.CloseNotifier); ok { + return cn.CloseNotify() + } + return nil } // Flush implements the http.Flusher interface. diff --git a/response_writer_test.go b/response_writer_test.go index dfc1d2c6..83d3fc8b 100644 --- a/response_writer_test.go +++ b/response_writer_test.go @@ -113,15 +113,18 @@ func TestResponseWriterHijack(t *testing.T) { writer.reset(testWriter) w := ResponseWriter(writer) - assert.Panics(t, func() { - _, _, err := w.Hijack() - require.NoError(t, err) - }) - assert.True(t, w.Written()) + // httptest.ResponseRecorder doesn't implement http.Hijacker; return + // http.ErrNotSupported instead of panicking (#4638). On unsupported the + // writer state stays untouched so the handler can still emit a normal + // HTTP response as a fallback. + conn, buf, err := w.Hijack() + assert.Nil(t, conn) + assert.Nil(t, buf) + require.ErrorIs(t, err, http.ErrNotSupported) + assert.False(t, w.Written()) - assert.Panics(t, func() { - w.CloseNotify() - }) + // CloseNotify on a non-CloseNotifier returns nil instead of panicking. + assert.Nil(t, w.CloseNotify()) w.Flush() } From 2e4d4f38962a6f15ae496d59b294f307eef95429 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Mon, 22 Jun 2026 19:00:06 +0800 Subject: [PATCH 44/70] chore(deps): bump github.com/quic-go/quic-go to v0.60.0 (#4713) - Upgrade quic-go from v0.59.0 to v0.60.0 --- go.mod | 2 +- go.sum | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index df181253..705034ee 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/mattn/go-isatty v0.0.20 github.com/modern-go/reflect2 v1.0.2 github.com/pelletier/go-toml/v2 v2.2.4 - github.com/quic-go/quic-go v0.59.0 + github.com/quic-go/quic-go v0.60.0 github.com/stretchr/testify v1.11.1 github.com/ugorji/go/codec v1.3.1 go.mongodb.org/mongo-driver/v2 v2.5.0 diff --git a/go.sum b/go.sum index f7f9e27b..c38e6eae 100644 --- a/go.sum +++ b/go.sum @@ -50,10 +50,12 @@ github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0 github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/quic-go/go-ossfuzz-seeds v0.1.0 h1:APacT+iIaNF6fd8AGEiN3bT/Jtkd2jz4v4TzM7MFjy0= +github.com/quic-go/go-ossfuzz-seeds v0.1.0/go.mod h1:3IOHRbJIc+L6YKMwfDtJAM9Vj9k0YY4muhuyUYk5tbk= github.com/quic-go/qpack v0.6.0 h1:g7W+BMYynC1LbYLSqRt8PBg5Tgwxn214ZZR34VIOjz8= github.com/quic-go/qpack v0.6.0/go.mod h1:lUpLKChi8njB4ty2bFLX2x4gzDqXwUpaO1DP9qMDZII= -github.com/quic-go/quic-go v0.59.0 h1:OLJkp1Mlm/aS7dpKgTc6cnpynnD2Xg7C1pwL6vy/SAw= -github.com/quic-go/quic-go v0.59.0/go.mod h1:upnsH4Ju1YkqpLXC305eW3yDZ4NfnNbmQRCMWS58IKU= +github.com/quic-go/quic-go v0.60.0 h1:xcQioE8OM66UQLeUMHltK1CCcOu3JbVB4JAQdDQSB+0= +github.com/quic-go/quic-go v0.60.0/go.mod h1:wpKpjmPpftl30sL6pFh7REVpjbcCVy4zt2vDyK1TuJk= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= From 293ad7edebb3ae30369288bd6416ca0d78474727 Mon Sep 17 00:00:00 2001 From: Amirhf Date: Mon, 22 Jun 2026 14:39:26 +0330 Subject: [PATCH 45/70] fix(context): Copy() copies Errors and Accepted fields (#4695) * Previously, Copy() only copied Keys and Params, leaving Errors and Accepted as nil even when set on the original context. Goroutines receiving a copied context could not observe errors attached before the copy, and content-negotiation state set by middleware was silently lost. * Replace assert.Equal(t, len(c.Errors), len(cp.Errors)) with assert.Len(t, cp.Errors, 2) to satisfy the testifylint linter rule --------- Co-authored-by: Bo-Yi Wu --- context.go | 10 ++++++++++ context_test.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/context.go b/context.go index a2e28e5b..640e20b2 100644 --- a/context.go +++ b/context.go @@ -141,6 +141,16 @@ func (c *Context) Copy() *Context { cp.Params = make([]Param, len(cParams)) copy(cp.Params, cParams) + if c.Errors != nil { + cp.Errors = make(errorMsgs, len(c.Errors)) + copy(cp.Errors, c.Errors) + } + + if c.Accepted != nil { + cp.Accepted = make([]string, len(c.Accepted)) + copy(cp.Accepted, c.Accepted) + } + return &cp } diff --git a/context_test.go b/context_test.go index 364a92ae..2dfdd392 100644 --- a/context_test.go +++ b/context_test.go @@ -689,6 +689,50 @@ func TestContextCopy(t *testing.T) { assert.Equal(t, cp.fullPath, c.fullPath) } +func TestContextCopyCopiesErrors(t *testing.T) { + c, _ := CreateTestContext(httptest.NewRecorder()) + c.Request, _ = http.NewRequest(http.MethodGet, "/", nil) + _ = c.Error(errors.New("first error")) + _ = c.Error(errors.New("second error")) + + cp := c.Copy() + + // copied context has the same errors + assert.Len(t, cp.Errors, 2) + assert.Equal(t, c.Errors[0].Error(), cp.Errors[0].Error()) + assert.Equal(t, c.Errors[1].Error(), cp.Errors[1].Error()) + + // mutations on the copy do not affect the original + _ = cp.Error(errors.New("third error")) + assert.Len(t, c.Errors, 2) + assert.Len(t, cp.Errors, 3) +} + +func TestContextCopyCopiesAccepted(t *testing.T) { + c, _ := CreateTestContext(httptest.NewRecorder()) + c.Request, _ = http.NewRequest(http.MethodGet, "/", nil) + c.SetAccepted("application/json", "text/html") + + cp := c.Copy() + + assert.Equal(t, c.Accepted, cp.Accepted) + + // mutations on the copy do not affect the original + cp.SetAccepted("text/plain") + assert.Equal(t, []string{"application/json", "text/html"}, c.Accepted) + assert.Equal(t, []string{"text/plain"}, cp.Accepted) +} + +func TestContextCopyNilErrorsAndAccepted(t *testing.T) { + c, _ := CreateTestContext(httptest.NewRecorder()) + c.Request, _ = http.NewRequest(http.MethodGet, "/", nil) + + cp := c.Copy() + + assert.Nil(t, cp.Errors) + assert.Nil(t, cp.Accepted) +} + func TestContextHandlerName(t *testing.T) { c, _ := CreateTestContext(httptest.NewRecorder()) c.handlers = HandlersChain{func(c *Context) {}, handlerNameTest} From 4a3eb31fb15b2a2d78b4bdbe0c31a2c564b1977a Mon Sep 17 00:00:00 2001 From: DadaVinqi Date: Mon, 22 Jun 2026 20:56:28 +0800 Subject: [PATCH 46/70] fix(recovery): record recovered panics in c.Errors (#4698) * fix: record recovered panic errors * chore(deps): bump quic-go to v0.59.1 * refactor(recovery): simplify panic error recording - Collapse the if/else into a single c.Error call in defaultHandleRecovery - Assert the recorded panic error is ErrorTypePrivate in the test Co-Authored-By: Claude Opus 4.8 (1M context) --------- Co-authored-by: m0_66095053 <2876430886@qq.com> Co-authored-by: Bo-Yi Wu Co-authored-by: Claude Opus 4.8 (1M context) --- recovery.go | 7 ++++++- recovery_test.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/recovery.go b/recovery.go index bbf1d565..2124fe5f 100644 --- a/recovery.go +++ b/recovery.go @@ -106,7 +106,12 @@ func secureRequestDump(r *http.Request) string { return strings.Join(lines, "\r\n") } -func defaultHandleRecovery(c *Context, _ any) { +func defaultHandleRecovery(c *Context, err any) { + e, ok := err.(error) + if !ok { + e = fmt.Errorf("%v", err) + } + c.Error(e) //nolint: errcheck c.AbortWithStatus(http.StatusInternalServerError) } diff --git a/recovery_test.go b/recovery_test.go index 028c4ad6..e5211790 100644 --- a/recovery_test.go +++ b/recovery_test.go @@ -5,6 +5,7 @@ package gin import ( + "errors" "net" "net/http" "os" @@ -152,6 +153,49 @@ func TestPanicWithAbortHandler(t *testing.T) { assert.NotContains(t, out, "panic recovered") } +func TestPanicInHandlerRecordsError(t *testing.T) { + tests := []struct { + name string + recoveredErr any + expectedErr string + }{ + { + name: "string panic", + recoveredErr: "Oops, Houston, we have a problem", + expectedErr: "Oops, Houston, we have a problem", + }, + { + name: "error panic", + recoveredErr: errors.New("recovered error"), + expectedErr: "recovered error", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + router := New() + + var recoveredErrors errorMsgs + router.Use(func(c *Context) { + c.Next() + recoveredErrors = c.Errors + }) + router.Use(RecoveryWithWriter(nil)) + router.GET("/recovery", func(_ *Context) { + panic(tt.recoveredErr) + }) + + w := PerformRequest(router, http.MethodGet, "/recovery") + + assert.Equal(t, http.StatusInternalServerError, w.Code) + if assert.Len(t, recoveredErrors, 1) { + assert.EqualError(t, recoveredErrors[0], tt.expectedErr) + assert.Equal(t, ErrorTypePrivate, recoveredErrors[0].Type) + } + }) + } +} + func TestCustomRecoveryWithWriter(t *testing.T) { errBuffer := new(strings.Builder) buffer := new(strings.Builder) From 074b669a95fd834701359acc55371e6b377618f6 Mon Sep 17 00:00:00 2001 From: MuaazTasawar Date: Mon, 22 Jun 2026 18:18:24 +0500 Subject: [PATCH 47/70] test(response_writer): add tests for Flush() with and without http.Flusher (#4699) * test(response_writer): add tests for Flush() with and without http.Flusher * test(response_writer): drop stray comment and clarify Flush regression note - Remove orphaned doc comment left at the end of the file - Reword the issue #4460 reference to reflect the no-panic guard --------- Co-authored-by: Bo-Yi Wu --- response_writer_test.go | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/response_writer_test.go b/response_writer_test.go index 83d3fc8b..03417375 100644 --- a/response_writer_test.go +++ b/response_writer_test.go @@ -15,10 +15,33 @@ import ( "github.com/stretchr/testify/require" ) -// TODO -// func (w *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { -// func (w *responseWriter) CloseNotify() <-chan bool { -// func (w *responseWriter) Flush() { +// TestResponseWriterFlushWithFlusher verifies Flush() calls the underlying Flusher. +func TestResponseWriterFlushWithFlusher(t *testing.T) { + testWriter := httptest.NewRecorder() + writer := &responseWriter{ResponseWriter: testWriter} + writer.Flush() + assert.True(t, testWriter.Flushed) +} + +// TestResponseWriterFlushWithNonFlusher verifies Flush() is a no-op +// when the underlying ResponseWriter does not implement http.Flusher. +// Guards against the panic reported in https://github.com/gin-gonic/gin/issues/4460 +func TestResponseWriterFlushWithNonFlusher(t *testing.T) { + nonFlusher := &nonFlusherWriter{header: http.Header{}} + writer := &responseWriter{ResponseWriter: nonFlusher} + require.NotPanics(t, func() { + writer.Flush() + }) +} + +// nonFlusherWriter is a minimal http.ResponseWriter that does NOT implement http.Flusher. +type nonFlusherWriter struct { + header http.Header +} + +func (w *nonFlusherWriter) Header() http.Header { return w.header } +func (w *nonFlusherWriter) Write(b []byte) (int, error) { return len(b), nil } +func (w *nonFlusherWriter) WriteHeader(code int) {} var ( _ ResponseWriter = &responseWriter{} From da1e108614ecbbadfa5736b1b297b16121d23b9b Mon Sep 17 00:00:00 2001 From: "Pierre F." Date: Mon, 22 Jun 2026 16:43:44 +0200 Subject: [PATCH 48/70] test(context): use t.TempDir() for SaveUploadedFile permission test on WSL (#4709) * fix: change file creation to use c.Temp instead to work on wsl * test(context): use t.TempDir() in SaveUploadedFile failure test for WSL Mirror the WSL-portability fix applied to TestSaveUploadedFileWithPermission: write under t.TempDir() instead of a relative path so the test does not depend on the working directory's filesystem (drvfs reports 0o777 on WSL) and is cleaned up automatically. Co-Authored-By: Claude Opus 4.8 (1M context) --------- Co-authored-by: Bo-Yi Wu Co-authored-by: Claude Opus 4.8 (1M context) --- context_test.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/context_test.go b/context_test.go index 2dfdd392..d93e470f 100644 --- a/context_test.go +++ b/context_test.go @@ -248,13 +248,11 @@ func TestSaveUploadedFileWithPermission(t *testing.T) { require.NoError(t, err) assert.Equal(t, "permission_test", f.Filename) var mode fs.FileMode = 0o755 - require.NoError(t, c.SaveUploadedFile(f, "permission_test", mode)) - t.Cleanup(func() { - assert.NoError(t, os.Remove("permission_test")) - }) - info, err := os.Stat(filepath.Dir("permission_test")) + dst := filepath.Join(t.TempDir(), "subdir", "permission_test") + require.NoError(t, c.SaveUploadedFile(f, dst, mode)) + info, err := os.Stat(filepath.Dir(dst)) require.NoError(t, err) - assert.Equal(t, info.Mode().Perm(), mode) + assert.Equal(t, mode, info.Mode().Perm()) } func TestSaveUploadedFileWithPermissionFailed(t *testing.T) { @@ -272,7 +270,8 @@ func TestSaveUploadedFileWithPermissionFailed(t *testing.T) { require.NoError(t, err) assert.Equal(t, "permission_test", f.Filename) var mode fs.FileMode = 0o644 - require.Error(t, c.SaveUploadedFile(f, "test/permission_test", mode)) + dst := filepath.Join(t.TempDir(), "test", "permission_test") + require.Error(t, c.SaveUploadedFile(f, dst, mode)) } func TestContextReset(t *testing.T) { From d9307dbcbbe796a64d9e0ef23452da888dd7f904 Mon Sep 17 00:00:00 2001 From: Muhammad Ardy Junata Date: Mon, 22 Jun 2026 22:34:41 +0700 Subject: [PATCH 49/70] fix(context): skip chmod on pre-existing dirs in SaveUploadedFile (#4702) * fix: skip chmod on pre-existing dirs in SaveUploadedFile Fixes #4622 Prior to this change, SaveUploadedFile unconditionally called os.Chmod(dir, mode) after os.MkdirAll, even when the target directory already existed. This caused 'operation not permitted' errors when saving files into system-owned directories like /tmp that the current process does not own. The fix uses os.Stat before MkdirAll to detect whether the directory already exists, and only calls os.Chmod when the directory was freshly created by MkdirAll. This restores the behaviour from v1.10.1 where only os.MkdirAll was used (which correctly skips permission changes on existing dirs) while preserving the custom permission feature added in v1.12.0. Regression test added: TestSaveUploadedFileToExistingDir saves a file into os.TempDir() (a pre-existing system directory) and asserts no error is returned. * test: make SaveUploadedFile #4622 regression test platform-independent The regression test relied on os.Chmod failing on a pre-existing directory, which only happens for a non-owner, non-root process. When tests run as root (common in containers/CI) or with a user-owned $TMPDIR, the buggy chmod succeeds, so the test passed even against the unfixed code. Assert the actual contract instead: a pre-existing directory's permissions are left unchanged. This catches the regression deterministically on every platform. Also tighten the SaveUploadedFile doc/comments: the requested perm is enforced only on the newly created destination directory, not on every directory in the path. Co-Authored-By: Claude Opus 4.8 (1M context) --------- Co-authored-by: Bo-Yi Wu Co-authored-by: Claude Opus 4.8 (1M context) --- context.go | 17 +++++++++++++++-- context_test.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/context.go b/context.go index 640e20b2..893edb28 100644 --- a/context.go +++ b/context.go @@ -726,6 +726,11 @@ func (c *Context) MultipartForm() (*multipart.Form, error) { } // SaveUploadedFile uploads the form file to specific dst. +// An optional perm argument specifies the permission bits used when creating +// the destination directory. If not provided, the default is 0750. The exact +// permission is enforced only on the destination directory and only when it is +// newly created by this call; pre-existing directories (e.g. /tmp) are not +// modified. func (c *Context) SaveUploadedFile(file *multipart.FileHeader, dst string, perm ...fs.FileMode) error { src, err := file.Open() if err != nil { @@ -738,11 +743,19 @@ func (c *Context) SaveUploadedFile(file *multipart.FileHeader, dst string, perm mode = perm[0] } dir := filepath.Dir(dst) + // Record whether the destination directory exists before MkdirAll, so we + // only chmod a directory we just created. Chmod'ing a pre-existing directory + // the process does not own (e.g. /tmp) fails with "operation not permitted" + // (#4622). A non-ErrNotExist stat error also skips chmod and lets MkdirAll + // surface the underlying failure. + _, statErr := os.Stat(dir) if err = os.MkdirAll(dir, mode); err != nil { return err } - if err = os.Chmod(dir, mode); err != nil { - return err + if errors.Is(statErr, os.ErrNotExist) { + if err = os.Chmod(dir, mode); err != nil { + return err + } } out, err := os.Create(dst) diff --git a/context_test.go b/context_test.go index d93e470f..e8d305e4 100644 --- a/context_test.go +++ b/context_test.go @@ -274,6 +274,50 @@ func TestSaveUploadedFileWithPermissionFailed(t *testing.T) { require.Error(t, c.SaveUploadedFile(f, dst, mode)) } +// TestSaveUploadedFileToExistingDir is a regression test for issue #4622. +// SaveUploadedFile must not call os.Chmod on a directory that already exists, +// because the process may not own it (e.g. /tmp on Linux/macOS), where chmod +// fails with "operation not permitted". This asserts the behavioral contract +// directly — a pre-existing directory's permissions are left unchanged — so it +// catches the regression on every platform, including environments (root/CI, +// user-owned $TMPDIR) where chmod on the temp dir would otherwise succeed. +func TestSaveUploadedFileToExistingDir(t *testing.T) { + buf := new(bytes.Buffer) + mw := multipart.NewWriter(buf) + w, err := mw.CreateFormFile("file", "existing_dir_test") + require.NoError(t, err) + _, err = w.Write([]byte("existing_dir_test")) + require.NoError(t, err) + mw.Close() + + c, _ := CreateTestContext(httptest.NewRecorder()) + c.Request, _ = http.NewRequest(http.MethodPost, "/", buf) + c.Request.Header.Set("Content-Type", mw.FormDataContentType()) + f, err := c.FormFile("file") + require.NoError(t, err) + + // A pre-existing directory owned by this process, set to a known mode. + dir := t.TempDir() + require.NoError(t, os.Chmod(dir, 0o700)) + + // Pass a perm that differs from the directory's current mode. The fix must + // not apply it to the pre-existing directory; the old code chmod'd it + // unconditionally, which also failed outright on unowned dirs like /tmp. + dst := filepath.Join(dir, "existing_dir_test.txt") + require.NoError(t, c.SaveUploadedFile(f, dst, 0o755)) + + // The pre-existing directory's permissions must be unchanged. + info, err := os.Stat(dir) + require.NoError(t, err) + assert.Equal(t, os.FileMode(0o700), info.Mode().Perm(), + "permissions of a pre-existing directory must not be modified") + + // The file must still be written with the correct content. + content, err := os.ReadFile(dst) + require.NoError(t, err) + assert.Equal(t, "existing_dir_test", string(content)) +} + func TestContextReset(t *testing.T) { router := New() c := router.allocateContext(0) From 03f3e420a3c370659359fb4deb99a474229b215a Mon Sep 17 00:00:00 2001 From: Hershel1995 Date: Tue, 23 Jun 2026 14:08:30 +0200 Subject: [PATCH 50/70] update validator library to version 10.30.3 (#4707) Co-authored-by: Carmelo Sottile --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 705034ee..4421641e 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.25.0 require ( github.com/bytedance/sonic v1.15.0 github.com/gin-contrib/sse v1.1.0 - github.com/go-playground/validator/v10 v10.30.1 + github.com/go-playground/validator/v10 v10.30.3 github.com/goccy/go-json v0.10.6 github.com/goccy/go-yaml v1.19.2 github.com/json-iterator/go v1.1.12 @@ -39,7 +39,7 @@ require ( github.com/twitchyliquid64/golang-asm v0.15.1 // indirect go.uber.org/mock v0.6.0 // indirect golang.org/x/arch v0.25.0 // indirect - golang.org/x/crypto v0.51.0 // indirect + golang.org/x/crypto v0.52.0 // indirect golang.org/x/sys v0.45.0 // indirect golang.org/x/text v0.37.0 // indirect ) diff --git a/go.sum b/go.sum index c38e6eae..a83985ba 100644 --- a/go.sum +++ b/go.sum @@ -20,8 +20,8 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.30.1 h1:f3zDSN/zOma+w6+1Wswgd9fLkdwy06ntQJp0BBvFG0w= -github.com/go-playground/validator/v10 v10.30.1/go.mod h1:oSuBIQzuJxL//3MelwSLD5hc2Tu889bF0Idm9Dg26cM= +github.com/go-playground/validator/v10 v10.30.3 h1:4MU6YkEwx7GbcPJOZxrtbu+QfF3pJLJuaYTeAH0DYy8= +github.com/go-playground/validator/v10 v10.30.3/go.mod h1:4Axh7oCNGcoGkqLoE4YWt6n20mcEIsPRlB7vPk3lpyc= github.com/goccy/go-json v0.10.6 h1:p8HrPJzOakx/mn/bQtjgNjdTcN+/S6FcG2CTtQOrHVU= github.com/goccy/go-json v0.10.6/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= github.com/goccy/go-yaml v1.19.2 h1:PmFC1S6h8ljIz6gMRBopkjP1TVT7xuwrButHID66PoM= @@ -79,8 +79,8 @@ go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y= go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU= golang.org/x/arch v0.25.0 h1:qnk6Ksugpi5Bz32947rkUgDt9/s5qvqDPl/gBKdMJLE= golang.org/x/arch v0.25.0/go.mod h1:0X+GdSIP+kL5wPmpK7sdkEVTt2XoYP0cSjQSbZBwOi8= -golang.org/x/crypto v0.51.0 h1:IBPXwPfKxY7cWQZ38ZCIRPI50YLeevDLlLnyC5wRGTI= -golang.org/x/crypto v0.51.0/go.mod h1:8AdwkbraGNABw2kOX6YFPs3WM22XqI4EXEd8g+x7Oc8= +golang.org/x/crypto v0.52.0 h1:RMs7fP2rXdep0CftQlK8Uf+kibLm7qkCcradZWYz988= +golang.org/x/crypto v0.52.0/go.mod h1:1QgfPxDqh0T2M/elOJtp9RvuR95kVjir0e6/BvEmGbc= golang.org/x/net v0.55.0 h1:bcvxaJn3e1U6InsFWt1JUq1aSjnRxLzT2rtD2KfkDF8= golang.org/x/net v0.55.0/go.mod h1:L5U2KuzuOe1lY7Z+aWVIKK6qEeJXnXV9yzGA+WCHJww= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= From 34dac209ffb6ef85cc78c5d217bbb7ad001d68fd Mon Sep 17 00:00:00 2001 From: greymoth Date: Sat, 27 Jun 2026 01:48:16 +0900 Subject: [PATCH 51/70] docs: fix `BindXML` comment referencing nonexistent `binding.BindXML` (#4717) The doc comment on line 790 read: "BindXML is a shortcut for c.MustBindWith(obj, binding.BindXML)." `binding.BindXML` does not exist. The correct symbol is `binding.XML` (defined in binding/binding.go), which is also what the implementation uses. All sibling methods (BindJSON, BindYAML, BindTOML, etc.) already reference the correct symbol in their comments. --- context.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/context.go b/context.go index 893edb28..1dc730e3 100644 --- a/context.go +++ b/context.go @@ -787,7 +787,7 @@ func (c *Context) BindJSON(obj any) error { return c.MustBindWith(obj, binding.JSON) } -// BindXML is a shortcut for c.MustBindWith(obj, binding.BindXML). +// BindXML is a shortcut for c.MustBindWith(obj, binding.XML). func (c *Context) BindXML(obj any) error { return c.MustBindWith(obj, binding.XML) } From 00cfe5aac2604e0632ee674b69a1e652a2461923 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 15 Aug 2026 13:42:11 +0800 Subject: [PATCH 52/70] chore(deps): bump the actions group across 1 directory with 4 updates (#4787) Bumps the actions group with 4 updates in the / directory: [actions/checkout](https://github.com/actions/checkout), [actions/setup-go](https://github.com/actions/setup-go), [actions/cache](https://github.com/actions/cache) and [codecov/codecov-action](https://github.com/codecov/codecov-action). Updates `actions/checkout` from 6 to 7 - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v6...v7) Updates `actions/setup-go` from 6 to 7 - [Release notes](https://github.com/actions/setup-go/releases) - [Commits](https://github.com/actions/setup-go/compare/v6...v7) Updates `actions/cache` from 5 to 6 - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/v5...v6) Updates `codecov/codecov-action` from 6 to 7 - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/codecov/codecov-action/compare/v6...v7) --- updated-dependencies: - dependency-name: actions/checkout dependency-version: '7' dependency-type: direct:production update-type: version-update:semver-major dependency-group: actions - dependency-name: actions/setup-go dependency-version: '7' dependency-type: direct:production update-type: version-update:semver-major dependency-group: actions - dependency-name: actions/cache dependency-version: '6' dependency-type: direct:production update-type: version-update:semver-major dependency-group: actions - dependency-name: codecov/codecov-action dependency-version: '7' dependency-type: direct:production update-type: version-update:semver-major dependency-group: actions ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql.yml | 2 +- .github/workflows/gin.yml | 12 ++++++------ .github/workflows/goreleaser.yml | 4 ++-- .github/workflows/trivy-scan.yml | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index f287c265..0ede2a05 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -33,7 +33,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v6 + uses: actions/checkout@v7 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/gin.yml b/.github/workflows/gin.yml index 8857bebc..072312dd 100644 --- a/.github/workflows/gin.yml +++ b/.github/workflows/gin.yml @@ -16,11 +16,11 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v6 + uses: actions/checkout@v7 with: fetch-depth: 0 - name: Set up Go - uses: actions/setup-go@v6 + uses: actions/setup-go@v7 with: go-version: "^1" - name: Setup golangci-lint @@ -55,17 +55,17 @@ jobs: GOPROXY: https://proxy.golang.org steps: - name: Set up Go ${{ matrix.go }} - uses: actions/setup-go@v6 + uses: actions/setup-go@v7 with: go-version: ${{ matrix.go }} cache: false - name: Checkout Code - uses: actions/checkout@v6 + uses: actions/checkout@v7 with: ref: ${{ github.ref }} - - uses: actions/cache@v5 + - uses: actions/cache@v6 with: path: | ${{ matrix.go-build }} @@ -78,6 +78,6 @@ jobs: run: make test - name: Upload coverage to Codecov - uses: codecov/codecov-action@v6 + uses: codecov/codecov-action@v7 with: flags: ${{ matrix.os }},go-${{ matrix.go }},${{ matrix.test-tags }} diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml index ea933e7e..6dd36ff1 100644 --- a/.github/workflows/goreleaser.yml +++ b/.github/workflows/goreleaser.yml @@ -13,11 +13,11 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v6 + uses: actions/checkout@v7 with: fetch-depth: 0 - name: Set up Go - uses: actions/setup-go@v6 + uses: actions/setup-go@v7 with: go-version: "^1" - name: Run GoReleaser diff --git a/.github/workflows/trivy-scan.yml b/.github/workflows/trivy-scan.yml index 9060e45c..751d0106 100644 --- a/.github/workflows/trivy-scan.yml +++ b/.github/workflows/trivy-scan.yml @@ -22,7 +22,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v6 + uses: actions/checkout@v7 with: fetch-depth: 0 From 8dd20118ba9a9dfa18ebba99e33d6a59b0090436 Mon Sep 17 00:00:00 2001 From: Gaurav Patil <159000263+GP-09@users.noreply.github.com> Date: Sat, 15 Aug 2026 11:13:07 +0530 Subject: [PATCH 53/70] fix(deps): bump golang.org/x/net and golang.org/x/text to patched versions (#4807) The scheduled Trivy scan has been failing on master with two HIGH findings, and it fails every pull request along with it: - CVE-2026-56852, golang.org/x/text, denial of service, fixed in 0.39.0 - CVE-2026-46600, golang.org/x/net/dns/dnsmessage, denial of service, fixed in 0.56.0 Bump both to the first patched release. golang.org/x/crypto and golang.org/x/sys move with them as transitive requirements of x/net. Verified with the same settings the workflow uses: trivy fs --scanners vuln --severity CRITICAL,HIGH,MEDIUM \ --ignore-unfixed --exit-code 1 . which now exits 0. go build ./... and go test ./... pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Bo-Yi Wu --- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 4421641e..3f80e1c0 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/stretchr/testify v1.11.1 github.com/ugorji/go/codec v1.3.1 go.mongodb.org/mongo-driver/v2 v2.5.0 - golang.org/x/net v0.55.0 + golang.org/x/net v0.56.0 google.golang.org/protobuf v1.36.11 ) @@ -39,7 +39,7 @@ require ( github.com/twitchyliquid64/golang-asm v0.15.1 // indirect go.uber.org/mock v0.6.0 // indirect golang.org/x/arch v0.25.0 // indirect - golang.org/x/crypto v0.52.0 // indirect - golang.org/x/sys v0.45.0 // indirect - golang.org/x/text v0.37.0 // indirect + golang.org/x/crypto v0.53.0 // indirect + golang.org/x/sys v0.46.0 // indirect + golang.org/x/text v0.39.0 // indirect ) diff --git a/go.sum b/go.sum index a83985ba..f04ab19c 100644 --- a/go.sum +++ b/go.sum @@ -79,15 +79,15 @@ go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y= go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU= golang.org/x/arch v0.25.0 h1:qnk6Ksugpi5Bz32947rkUgDt9/s5qvqDPl/gBKdMJLE= golang.org/x/arch v0.25.0/go.mod h1:0X+GdSIP+kL5wPmpK7sdkEVTt2XoYP0cSjQSbZBwOi8= -golang.org/x/crypto v0.52.0 h1:RMs7fP2rXdep0CftQlK8Uf+kibLm7qkCcradZWYz988= -golang.org/x/crypto v0.52.0/go.mod h1:1QgfPxDqh0T2M/elOJtp9RvuR95kVjir0e6/BvEmGbc= -golang.org/x/net v0.55.0 h1:bcvxaJn3e1U6InsFWt1JUq1aSjnRxLzT2rtD2KfkDF8= -golang.org/x/net v0.55.0/go.mod h1:L5U2KuzuOe1lY7Z+aWVIKK6qEeJXnXV9yzGA+WCHJww= +golang.org/x/crypto v0.53.0 h1:QZ4Muo8THX6CizN2vPPd5fBGHyogrdK9fG4wLPFUsto= +golang.org/x/crypto v0.53.0/go.mod h1:DNLU434OwVakk9PzuwV8w62mAJpRJL3vsgcfp4Qnsio= +golang.org/x/net v0.56.0 h1:Rw8j/hFzGvJUZwNBXnAtf5sVDVt+65SK2C7IxCxZt5o= +golang.org/x/net v0.56.0/go.mod h1:D3Ku6r+V6JROoZK144D2XfMHFcMq/0zSfLelVTCFKec= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY= -golang.org/x/sys v0.45.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= -golang.org/x/text v0.37.0 h1:Cqjiwd9eSg8e0QAkyCaQTNHFIIzWtidPahFWR83rTrc= -golang.org/x/text v0.37.0/go.mod h1:a5sjxXGs9hsn/AJVwuElvCAo9v8QYLzvavO5z2PiM38= +golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw= +golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= +golang.org/x/text v0.39.0 h1:UbZz4pLOvn600D6Oh6GGEI6VAmndrEBLv8/6BEXzyus= +golang.org/x/text v0.39.0/go.mod h1:3UwRclnC2g0TU9x8PZiyfOajCd1zaUNHF9cvqcQZ+ZM= google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From dcaa4296d111981ffb31ac3eba90bb63e1eb5ab9 Mon Sep 17 00:00:00 2001 From: Amirhf Date: Sat, 15 Aug 2026 09:14:19 +0330 Subject: [PATCH 54/70] docs(path): fix malformed comment in cleanPath (#4723) --- path.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/path.go b/path.go index 3b67caa9..672213d1 100644 --- a/path.go +++ b/path.go @@ -55,7 +55,7 @@ func cleanPath(p string) string { // A bit more clunky without a 'lazybuf' like the path package, but the loop // gets completely inlined (bufApp calls). - // loop has no expensive function calls (except 1x make) // So in contrast to the path package this loop has no expensive function + // So in contrast to the path package this loop has no expensive function // calls (except make, if needed). for r < n { From 2a1a14ff37a26ca6a76763ecc33727c23d9284e9 Mon Sep 17 00:00:00 2001 From: Jia-ben00 <2403877005@qq.com> Date: Wed, 16 Sep 2026 21:24:33 +0800 Subject: [PATCH 55/70] feat(router): add QUERY method shortcut for RFC 10008 (#4830) * feat(router): add QUERY method shortcut for RFC 10008 Add a QUERY() router method as a shortcut for Handle("QUERY", path, handlers), following the same pattern as GET, POST, HEAD and other HTTP method shortcuts. The QUERY method is defined by RFC 10008 and allows sending a query in the request body, similar to GET but with a body. Go's net/http does not yet expose an http.MethodQuery constant, so the literal string "QUERY" is used. Closes #4721 * style(router): format QUERY method test - Remove an extra blank line to satisfy gofmt. --------- Co-authored-by: Jia-ben00 <316397950+Jia-ben00@users.noreply.github.com> Co-authored-by: Bo-Yi Wu --- gin_test.go | 19 +++++++++++++++++++ routergroup.go | 7 +++++++ 2 files changed, 26 insertions(+) diff --git a/gin_test.go b/gin_test.go index a9cf1755..b488c446 100644 --- a/gin_test.go +++ b/gin_test.go @@ -1156,3 +1156,22 @@ func TestUpdateRouteTreesCalledOnce(t *testing.T) { assert.Equal(t, "ok", w.Body.String()) } } + +func TestRouterQueryMethod(t *testing.T) { + router := New() + router.QUERY("/test", func(c *Context) { + c.String(http.StatusOK, "query ok") + }) + + w := httptest.NewRecorder() + req, _ := http.NewRequest("QUERY", "/test", nil) + router.ServeHTTP(w, req) + assert.Equal(t, http.StatusOK, w.Code) + assert.Equal(t, "query ok", w.Body.String()) + + // Other methods should not match + w2 := httptest.NewRecorder() + req2, _ := http.NewRequest(http.MethodGet, "/test", nil) + router.ServeHTTP(w2, req2) + assert.Equal(t, http.StatusNotFound, w2.Code) +} diff --git a/routergroup.go b/routergroup.go index c01b917e..1ae0b7b4 100644 --- a/routergroup.go +++ b/routergroup.go @@ -142,6 +142,13 @@ func (group *RouterGroup) HEAD(relativePath string, handlers ...HandlerFunc) IRo return group.handle(http.MethodHead, relativePath, handlers) } +// QUERY is a shortcut for router.Handle("QUERY", path, handlers). +// The QUERY method is defined by RFC 10008 and is used to send a query +// in the request body, similar to GET but with a body. +func (group *RouterGroup) QUERY(relativePath string, handlers ...HandlerFunc) IRoutes { + return group.handle("QUERY", relativePath, handlers) +} + // Any registers a route that matches all the HTTP methods. // GET, POST, PUT, PATCH, HEAD, OPTIONS, DELETE, CONNECT, TRACE. func (group *RouterGroup) Any(relativePath string, handlers ...HandlerFunc) IRoutes { From b52df1fe77734c691acc1fce21647fe0ca955201 Mon Sep 17 00:00:00 2001 From: Ruben Pari <73421813+RubenPari@users.noreply.github.com> Date: Wed, 16 Sep 2026 15:26:35 +0200 Subject: [PATCH 56/70] docs: document panic conditions in Handle, StaticFS, and Bind (#4797) Handle panics on invalid HTTP method, StaticFS panics when relativePath contains URL parameters, and Bind panics when given a pointer. These panic conditions are reasonable startup-time guards but were not documented, making the crash risk undiscoverable without reading source. Fixes #4594 --- routergroup.go | 3 +++ utils.go | 1 + 2 files changed, 4 insertions(+) diff --git a/routergroup.go b/routergroup.go index 1ae0b7b4..84d3e00b 100644 --- a/routergroup.go +++ b/routergroup.go @@ -100,6 +100,8 @@ func (group *RouterGroup) handle(httpMethod, relativePath string, handlers Handl // This function is intended for bulk loading and to allow the usage of less // frequently used, non-standardized or custom methods (e.g. for internal // communication with a proxy). +// +// It panics if httpMethod is not a valid HTTP method (uppercase ASCII letters only). func (group *RouterGroup) Handle(httpMethod, relativePath string, handlers ...HandlerFunc) IRoutes { if matched := regEnLetter.MatchString(httpMethod); !matched { panic("http method " + httpMethod + " is not valid") @@ -207,6 +209,7 @@ func (group *RouterGroup) Static(relativePath, root string) IRoutes { // StaticFS works just like `Static()` but a custom `http.FileSystem` can be used instead. // Gin by default uses: gin.Dir() +// It panics if relativePath contains URL parameters (: or *). func (group *RouterGroup) StaticFS(relativePath string, fs http.FileSystem) IRoutes { if strings.Contains(relativePath, ":") || strings.Contains(relativePath, "*") { panic("URL parameters can not be used when serving a static folder") diff --git a/utils.go b/utils.go index 2fecce46..ac221def 100644 --- a/utils.go +++ b/utils.go @@ -26,6 +26,7 @@ const localhostIP = "127.0.0.1" const localhostIPv6 = "::1" // Bind is a helper function for given interface object and returns a Gin middleware. +// It panics if val is a pointer; pass the struct value directly (e.g., gin.Bind(Struct{}) not gin.Bind(&Struct{})). func Bind(val any) HandlerFunc { value := reflect.ValueOf(val) if value.Kind() == reflect.Ptr { From bc141b4dbf90d5bb5028fc68afe48782402bb2d4 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Wed, 16 Sep 2026 22:47:17 +0800 Subject: [PATCH 57/70] fix(deps)!: patch x/crypto vulnerabilities (#4832) - Upgrade x/crypto and its required dependency versions - Align documentation and CI with the required Go version BREAKING CHANGE: Go 1.26 or later is now required by x/crypto v0.56.0. Upgrade the Go toolchain before building Gin. --- .github/workflows/gin.yml | 2 +- README.md | 2 +- go.mod | 10 +++++----- go.sum | 16 ++++++++-------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/gin.yml b/.github/workflows/gin.yml index 072312dd..eb463fee 100644 --- a/.github/workflows/gin.yml +++ b/.github/workflows/gin.yml @@ -33,7 +33,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest] - go: ["1.25", "1.26"] + go: ["1.26", "1.27"] test-tags: [ "", diff --git a/README.md b/README.md index 96b0ae3c..10e627fc 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ Gin combines the simplicity of Express.js-style routing with Go's performance ch ### Prerequisites -- **Go version**: Gin requires [Go](https://go.dev/) version [1.25](https://go.dev/doc/devel/release#go1.25.0) or above +- **Go version**: Gin requires [Go](https://go.dev/) version [1.26](https://go.dev/doc/devel/release#go1.26.0) or above - **Basic Go knowledge**: Familiarity with Go syntax and package management is helpful ### Installation diff --git a/go.mod b/go.mod index 3f80e1c0..5ede85b2 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/gin-gonic/gin -go 1.25.0 +go 1.26.0 require ( github.com/bytedance/sonic v1.15.0 @@ -16,7 +16,7 @@ require ( github.com/stretchr/testify v1.11.1 github.com/ugorji/go/codec v1.3.1 go.mongodb.org/mongo-driver/v2 v2.5.0 - golang.org/x/net v0.56.0 + golang.org/x/net v0.57.0 google.golang.org/protobuf v1.36.11 ) @@ -39,7 +39,7 @@ require ( github.com/twitchyliquid64/golang-asm v0.15.1 // indirect go.uber.org/mock v0.6.0 // indirect golang.org/x/arch v0.25.0 // indirect - golang.org/x/crypto v0.53.0 // indirect - golang.org/x/sys v0.46.0 // indirect - golang.org/x/text v0.39.0 // indirect + golang.org/x/crypto v0.56.0 // indirect + golang.org/x/sys v0.47.0 // indirect + golang.org/x/text v0.41.0 // indirect ) diff --git a/go.sum b/go.sum index f04ab19c..a714fd58 100644 --- a/go.sum +++ b/go.sum @@ -79,15 +79,15 @@ go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y= go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU= golang.org/x/arch v0.25.0 h1:qnk6Ksugpi5Bz32947rkUgDt9/s5qvqDPl/gBKdMJLE= golang.org/x/arch v0.25.0/go.mod h1:0X+GdSIP+kL5wPmpK7sdkEVTt2XoYP0cSjQSbZBwOi8= -golang.org/x/crypto v0.53.0 h1:QZ4Muo8THX6CizN2vPPd5fBGHyogrdK9fG4wLPFUsto= -golang.org/x/crypto v0.53.0/go.mod h1:DNLU434OwVakk9PzuwV8w62mAJpRJL3vsgcfp4Qnsio= -golang.org/x/net v0.56.0 h1:Rw8j/hFzGvJUZwNBXnAtf5sVDVt+65SK2C7IxCxZt5o= -golang.org/x/net v0.56.0/go.mod h1:D3Ku6r+V6JROoZK144D2XfMHFcMq/0zSfLelVTCFKec= +golang.org/x/crypto v0.56.0 h1:GUh5Ii4J5jtcseSMiRqr1jXCNHoxjeV9Fmekc2oLy6Y= +golang.org/x/crypto v0.56.0/go.mod h1:OMW5y6CY9l38uPLmxU6l6pwcXp1obtLo3e6gT7gQR2I= +golang.org/x/net v0.57.0 h1:K5+3DljvIuDG9/Jv9rvyMywYNFCQ9RSUY6OOTTkT+tE= +golang.org/x/net v0.57.0/go.mod h1:KpXc8iv+r3XplLAG/f7Jsf9RPszJzdR0f58q9vGOuEU= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw= -golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= -golang.org/x/text v0.39.0 h1:UbZz4pLOvn600D6Oh6GGEI6VAmndrEBLv8/6BEXzyus= -golang.org/x/text v0.39.0/go.mod h1:3UwRclnC2g0TU9x8PZiyfOajCd1zaUNHF9cvqcQZ+ZM= +golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs= +golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= +golang.org/x/text v0.41.0 h1:vz/seA0lnX87Othu2f/0L24RcgrXD9/YFTSuGjj3rH8= +golang.org/x/text v0.41.0/go.mod h1:jvf1O8ajNzZqhSrQBPbutR/EB83Cc0CFrezNQIwbb5M= google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From 5c6a15f8f9566612076bd209e623861bf92a6283 Mon Sep 17 00:00:00 2001 From: Langning Zhang Date: Wed, 16 Sep 2026 23:01:52 +0800 Subject: [PATCH 58/70] fix(context): handle missing HTML renderer (#4805) * fix(context): handle missing HTML renderer * test(render): cover missing HTML renderer error --------- Co-authored-by: Bo-Yi Wu --- context.go | 5 +++ context_test.go | 76 +++++++++++++++++++++++++++++++++++++++++++ render/html.go | 6 ++++ render/render_test.go | 10 ++++++ 4 files changed, 97 insertions(+) diff --git a/context.go b/context.go index 1dc730e3..788b00bb 100644 --- a/context.go +++ b/context.go @@ -1219,6 +1219,11 @@ func (c *Context) Render(code int, r render.Render) { // It also updates the HTTP code and sets the Content-Type as "text/html". // See http://golang.org/doc/articles/wiki/ func (c *Context) HTML(code int, name string, obj any) { + if c.engine.HTMLRender == nil { + c.Render(code, render.HTML{}) + return + } + instance := c.engine.HTMLRender.Instance(name, obj) c.Render(code, instance) } diff --git a/context_test.go b/context_test.go index e8d305e4..cef488c9 100644 --- a/context_test.go +++ b/context_test.go @@ -1345,6 +1345,82 @@ func TestContextRenderHTML(t *testing.T) { assert.Equal(t, "text/html; charset=utf-8", w.Header().Get("Content-Type")) } +func TestContextRenderHTMLWithoutRenderer(t *testing.T) { + tests := []struct { + name string + method string + status int + wantErrors []string + wantAborted bool + wantNextCalled bool + }{ + { + name: "body allowed", + method: http.MethodGet, + status: http.StatusAccepted, + wantErrors: []string{"html renderer is not configured"}, + wantAborted: true, + }, + { + name: "no content", + method: http.MethodGet, + status: http.StatusNoContent, + wantNextCalled: true, + }, + { + name: "not modified", + method: http.MethodGet, + status: http.StatusNotModified, + wantNextCalled: true, + }, + { + name: "head", + method: http.MethodHead, + status: http.StatusOK, + wantErrors: []string{"html renderer is not configured"}, + wantAborted: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + w := httptest.NewRecorder() + router := New() + var contextErrors []string + var contextAborted bool + nextHandlerCalled := false + + handlers := []HandlerFunc{ + func(c *Context) { + c.HTML(tt.status, "index.tmpl", H{"title": "Main website"}) + contextErrors = c.Errors.Errors() + contextAborted = c.IsAborted() + }, + func(_ *Context) { + nextHandlerCalled = true + }, + } + if tt.method == http.MethodHead { + router.HEAD("/", handlers...) + } else { + router.GET("/", handlers...) + } + + req := httptest.NewRequest(tt.method, "/", nil) + require.NotPanics(t, func() { + router.ServeHTTP(w, req) + }) + + assert.Equal(t, tt.status, w.Code) + assert.Equal(t, "text/html; charset=utf-8", w.Header().Get("Content-Type")) + assert.Equal(t, tt.wantErrors, contextErrors) + assert.Equal(t, tt.wantAborted, contextAborted) + assert.Equal(t, tt.wantNextCalled, nextHandlerCalled) + assert.Empty(t, w.Body.String()) + }) + } +} + func TestContextRenderHTML2(t *testing.T) { w := httptest.NewRecorder() c, router := CreateTestContext(w) diff --git a/render/html.go b/render/html.go index 965d84c6..36c8f079 100644 --- a/render/html.go +++ b/render/html.go @@ -5,6 +5,7 @@ package render import ( + "errors" "html/template" "net/http" @@ -50,6 +51,8 @@ type HTML struct { var htmlContentType = []string{"text/html; charset=utf-8"} +var errHTMLRendererNotConfigured = errors.New("html renderer is not configured") + // Instance (HTMLProduction) returns an HTML instance which it realizes Render interface. func (r HTMLProduction) Instance(name string, data any) Render { return HTML{ @@ -88,6 +91,9 @@ func (r HTMLDebug) loadTemplate() *template.Template { // Render (HTML) executes template and writes its result with custom ContentType for response. func (r HTML) Render(w http.ResponseWriter) error { r.WriteContentType(w) + if r.Template == nil { + return errHTMLRendererNotConfigured + } if r.Name == "" { return r.Template.Execute(w, r.Data) diff --git a/render/render_test.go b/render/render_test.go index f63878b9..24815452 100644 --- a/render/render_test.go +++ b/render/render_test.go @@ -630,6 +630,16 @@ func TestRenderHTMLTemplate(t *testing.T) { assert.Equal(t, "text/html; charset=utf-8", w.Header().Get("Content-Type")) } +func TestRenderHTMLWithoutTemplate(t *testing.T) { + w := httptest.NewRecorder() + + err := (HTML{}).Render(w) + + require.EqualError(t, err, "html renderer is not configured") + assert.Empty(t, w.Body.String()) + assert.Equal(t, "text/html; charset=utf-8", w.Header().Get("Content-Type")) +} + func TestRenderHTMLTemplateEmptyName(t *testing.T) { w := httptest.NewRecorder() templ := template.Must(template.New("").Parse(`Hello {{.name}}`)) From 3329b63aa7c0b107dd6d72a74add233fe11485d8 Mon Sep 17 00:00:00 2001 From: Bob Du Date: Sat, 19 Sep 2026 14:09:40 +0800 Subject: [PATCH 59/70] ci(codecov): fix stale comparison base and invalid config (#4823) Signed-off-by: Bob Du Co-authored-by: Bo-Yi Wu --- .github/workflows/gin.yml | 4 ++++ codecov.yml | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/gin.yml b/.github/workflows/gin.yml index eb463fee..d0f42d09 100644 --- a/.github/workflows/gin.yml +++ b/.github/workflows/gin.yml @@ -30,6 +30,9 @@ jobs: args: --verbose test: needs: lint + permissions: + contents: read + id-token: write strategy: matrix: os: [ubuntu-latest, macos-latest] @@ -80,4 +83,5 @@ jobs: - name: Upload coverage to Codecov uses: codecov/codecov-action@v7 with: + use_oidc: true flags: ${{ matrix.os }},go-${{ matrix.go }},${{ matrix.test-tags }} diff --git a/codecov.yml b/codecov.yml index 47782e50..f78e4295 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,6 +1,7 @@ -coverage: +codecov: require_ci_to_pass: true +coverage: status: project: default: From e318c6add8f947ba3c0db15f782517a9bb6bedc2 Mon Sep 17 00:00:00 2001 From: daixiheguu Date: Sat, 19 Sep 2026 14:10:49 +0800 Subject: [PATCH 60/70] docs: align function comments with names (#4814) Signed-off-by: daixiheguu Co-authored-by: Bo-Yi Wu --- gin_integration_test.go | 1 + render/render_test.go | 4 ++-- response_writer_test.go | 3 ++- routes_test.go | 18 +++++++++--------- tree.go | 6 +++--- utils.go | 3 ++- 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/gin_integration_test.go b/gin_integration_test.go index 720b140f..da408d9c 100644 --- a/gin_integration_test.go +++ b/gin_integration_test.go @@ -25,6 +25,7 @@ import ( "github.com/stretchr/testify/require" ) +// testRequest sends a request and validates its response. // params[0]=url example:http://127.0.0.1:8080/index (cannot be empty) // params[1]=response status (custom compare status) default:"200 OK" // params[2]=response body (custom compare content) default:"it worked" diff --git a/render/render_test.go b/render/render_test.go index 24815452..a3f90a3f 100644 --- a/render/render_test.go +++ b/render/render_test.go @@ -283,7 +283,7 @@ func TestRenderPureJSON(t *testing.T) { type xmlmap map[string]any -// Allows type H to be used with xml.Marshal +// MarshalXML allows xmlmap to be used with xml.Marshal. func (h xmlmap) MarshalXML(e *xml.Encoder, start xml.StartElement) error { start.Name = xml.Name{ Space: "", @@ -331,7 +331,7 @@ b: type fail struct{} -// Hook MarshalYAML +// MarshalYAML returns an error for YAML rendering failure tests. func (ft *fail) MarshalYAML() (any, error) { return nil, errors.New("fail") } diff --git a/response_writer_test.go b/response_writer_test.go index 03417375..99548431 100644 --- a/response_writer_test.go +++ b/response_writer_test.go @@ -220,7 +220,8 @@ func TestResponseWriterHijackAfterWrite(t *testing.T) { } } -// Test: WebSocket compatibility - allow hijack after WriteHeaderNow(), but block after body data. +// TestResponseWriterHijackAfterWriteHeaderNow verifies that hijacking is allowed after +// WriteHeaderNow but blocked after body data is written. func TestResponseWriterHijackAfterWriteHeaderNow(t *testing.T) { tests := []struct { name string diff --git a/routes_test.go b/routes_test.go index 1cae3fce..1b7570b0 100644 --- a/routes_test.go +++ b/routes_test.go @@ -51,7 +51,7 @@ func testRouteOK(method string, t *testing.T) { assert.True(t, passedAny) } -// TestSingleRouteOK tests that POST route is correctly invoked. +// testRouteNotOK tests that a request with the wrong method returns a not found response. func testRouteNotOK(method string, t *testing.T) { passed := false router := New() @@ -65,7 +65,7 @@ func testRouteNotOK(method string, t *testing.T) { assert.Equal(t, http.StatusNotFound, w.Code) } -// TestSingleRouteOK tests that POST route is correctly invoked. +// testRouteNotOK2 tests that a request with the wrong method returns a method not allowed response. func testRouteNotOK2(method string, t *testing.T) { passed := false router := New() @@ -273,7 +273,7 @@ func TestRouteRedirectFixedPath(t *testing.T) { assert.Equal(t, http.StatusTemporaryRedirect, w.Code) } -// TestContextParamsGet tests that a parameter can be parsed from the URL. +// TestRouteParamsByName tests that route parameters can be parsed by name. func TestRouteParamsByName(t *testing.T) { name := "" lastName := "" @@ -305,7 +305,7 @@ func TestRouteParamsByName(t *testing.T) { assert.Equal(t, "/is/super/great", wild) } -// TestContextParamsGet tests that a parameter can be parsed from the URL even with extra slashes. +// TestRouteParamsByNameWithExtraSlash tests that route parameters can be parsed by name even with extra slashes. func TestRouteParamsByNameWithExtraSlash(t *testing.T) { name := "" lastName := "" @@ -377,7 +377,7 @@ func TestRouteParamsNotEmpty(t *testing.T) { assert.Equal(t, "/is/super/great", wild) } -// TestHandleStaticFile - ensure the static file handles properly +// TestRouteStaticFile tests that a static file is served correctly. func TestRouteStaticFile(t *testing.T) { // SETUP file testRoot, _ := os.Getwd() @@ -412,7 +412,7 @@ func TestRouteStaticFile(t *testing.T) { assert.Equal(t, http.StatusOK, w3.Code) } -// TestHandleStaticFile - ensure the static file handles properly +// TestRouteStaticFileFS tests that a static file from an http.FileSystem is served correctly. func TestRouteStaticFileFS(t *testing.T) { // SETUP file testRoot, _ := os.Getwd() @@ -446,7 +446,7 @@ func TestRouteStaticFileFS(t *testing.T) { assert.Equal(t, http.StatusOK, w3.Code) } -// TestHandleStaticDir - ensure the root/sub dir handles properly +// TestRouteStaticListingDir tests that static directory listing is enabled when configured. func TestRouteStaticListingDir(t *testing.T) { router := New() router.StaticFS("/", Dir("./", true)) @@ -458,7 +458,7 @@ func TestRouteStaticListingDir(t *testing.T) { assert.Equal(t, "text/html; charset=utf-8", w.Header().Get("Content-Type")) } -// TestHandleHeadToDir - ensure the root/sub dir handles properly +// TestRouteStaticNoListing tests that static directory listing is disabled by default. func TestRouteStaticNoListing(t *testing.T) { router := New() router.Static("/", "./") @@ -656,7 +656,7 @@ func TestRouterStaticFSFileNotFound(t *testing.T) { }) } -// Reproduction test for the bug of issue #1805 +// TestMiddlewareCalledOnceByRouterStaticFSNotFound reproduces the bug reported in issue #1805. func TestMiddlewareCalledOnceByRouterStaticFSNotFound(t *testing.T) { router := New() diff --git a/tree.go b/tree.go index 580abbaf..dc84ff61 100644 --- a/tree.go +++ b/tree.go @@ -107,7 +107,7 @@ type node struct { fullPath string } -// Increments priority of the given child and reorders if necessary +// incrementChildPrio increments the priority of the given child and reorders it if necessary. func (n *node) incrementChildPrio(pos int) int { cs := n.children cs[pos].priority++ @@ -683,7 +683,7 @@ func (n *node) findCaseInsensitivePath(path string, fixTrailingSlash bool) ([]by return ciPath, ciPath != nil } -// Shift bytes in array by n bytes left +// shiftNRuneBytes shifts bytes in the array n positions to the left. func shiftNRuneBytes(rb [4]byte, n int) [4]byte { switch n { case 0: @@ -699,7 +699,7 @@ func shiftNRuneBytes(rb [4]byte, n int) [4]byte { } } -// Recursive case-insensitive lookup function used by n.findCaseInsensitivePath +// findCaseInsensitivePathRec recursively performs a case-insensitive path lookup. func (n *node) findCaseInsensitivePathRec(path string, ciPath []byte, rb [4]byte, fixTrailingSlash bool) []byte { npLen := len(n.path) diff --git a/utils.go b/utils.go index ac221def..e8b86fcc 100644 --- a/utils.go +++ b/utils.go @@ -161,7 +161,8 @@ func resolveAddress(addr []string) string { } } -// https://stackoverflow.com/questions/53069040/checking-a-string-contains-only-ascii-characters +// isASCII reports whether s contains only ASCII characters. +// See https://stackoverflow.com/questions/53069040/checking-a-string-contains-only-ascii-characters. func isASCII(s string) bool { for i := range len(s) { if s[i] > unicode.MaxASCII { From 05b14df992a31fe8ff567338bb6c934f1aa3872f Mon Sep 17 00:00:00 2001 From: Bob Du Date: Sat, 19 Sep 2026 14:12:33 +0800 Subject: [PATCH 61/70] chore(deps): bump github.com/stretchr/testify to v1.12.1 (#4822) Signed-off-by: Bob Du Co-authored-by: Bo-Yi Wu --- go.mod | 8 ++------ go.sum | 17 ++++------------- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/go.mod b/go.mod index 5ede85b2..99a8d5bb 100644 --- a/go.mod +++ b/go.mod @@ -13,31 +13,27 @@ require ( github.com/modern-go/reflect2 v1.0.2 github.com/pelletier/go-toml/v2 v2.2.4 github.com/quic-go/quic-go v0.60.0 - github.com/stretchr/testify v1.11.1 + github.com/stretchr/testify v1.12.1 github.com/ugorji/go/codec v1.3.1 go.mongodb.org/mongo-driver/v2 v2.5.0 golang.org/x/net v0.57.0 google.golang.org/protobuf v1.36.11 ) -require gopkg.in/yaml.v3 v3.0.1 // indirect - require ( github.com/bytedance/gopkg v0.1.3 // indirect github.com/bytedance/sonic/loader v0.5.0 // indirect github.com/cloudwego/base64x v0.1.6 // indirect - github.com/davecgh/go-spew v1.1.1 // indirect github.com/gabriel-vasile/mimetype v1.4.13 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/klauspost/cpuid/v2 v2.3.0 // indirect - github.com/kr/text v0.2.0 // indirect github.com/leodido/go-urn v1.4.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect github.com/quic-go/qpack v0.6.0 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect go.uber.org/mock v0.6.0 // indirect + go.yaml.in/yaml/v3 v3.0.5 // indirect golang.org/x/arch v0.25.0 // indirect golang.org/x/crypto v0.56.0 // indirect golang.org/x/sys v0.47.0 // indirect diff --git a/go.sum b/go.sum index a714fd58..dc6ef902 100644 --- a/go.sum +++ b/go.sum @@ -6,7 +6,6 @@ github.com/bytedance/sonic/loader v0.5.0 h1:gXH3KVnatgY7loH5/TkeVyXPfESoqSBSBEiD github.com/bytedance/sonic/loader v0.5.0/go.mod h1:AR4NYCk5DdzZizZ5djGqQ92eEhCCcdf5x77udYiSJRo= github.com/cloudwego/base64x v0.1.6 h1:t11wG9AECkCDk5fMSoxmufanudBtJ+/HemLstXDLI2M= github.com/cloudwego/base64x v0.1.6/go.mod h1:OFcloc187FXDaYHvrNIjxSe8ncn0OOM8gEHfghB2IPU= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -33,10 +32,6 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y= github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0= -github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= -github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= -github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= @@ -48,7 +43,6 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4= github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/quic-go/go-ossfuzz-seeds v0.1.0 h1:APacT+iIaNF6fd8AGEiN3bT/Jtkd2jz4v4TzM7MFjy0= github.com/quic-go/go-ossfuzz-seeds v0.1.0/go.mod h1:3IOHRbJIc+L6YKMwfDtJAM9Vj9k0YY4muhuyUYk5tbk= @@ -56,8 +50,6 @@ github.com/quic-go/qpack v0.6.0 h1:g7W+BMYynC1LbYLSqRt8PBg5Tgwxn214ZZR34VIOjz8= github.com/quic-go/qpack v0.6.0/go.mod h1:lUpLKChi8njB4ty2bFLX2x4gzDqXwUpaO1DP9qMDZII= github.com/quic-go/quic-go v0.60.0 h1:xcQioE8OM66UQLeUMHltK1CCcOu3JbVB4JAQdDQSB+0= github.com/quic-go/quic-go v0.60.0/go.mod h1:wpKpjmPpftl30sL6pFh7REVpjbcCVy4zt2vDyK1TuJk= -github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= -github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -67,8 +59,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= -github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE= +github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go/codec v1.3.1 h1:waO7eEiFDwidsBN6agj1vJQ4AG7lh2yqXyOXqhgQuyY= @@ -77,6 +69,8 @@ go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0= go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y= go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU= +go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw= +go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg= golang.org/x/arch v0.25.0 h1:qnk6Ksugpi5Bz32947rkUgDt9/s5qvqDPl/gBKdMJLE= golang.org/x/arch v0.25.0/go.mod h1:0X+GdSIP+kL5wPmpK7sdkEVTt2XoYP0cSjQSbZBwOi8= golang.org/x/crypto v0.56.0 h1:GUh5Ii4J5jtcseSMiRqr1jXCNHoxjeV9Fmekc2oLy6Y= @@ -91,8 +85,5 @@ golang.org/x/text v0.41.0/go.mod h1:jvf1O8ajNzZqhSrQBPbutR/EB83Cc0CFrezNQIwbb5M= google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From b1f77cf536154f67e3332fc5d0965b891be86606 Mon Sep 17 00:00:00 2001 From: Gaurav Patil <159000263+GP-09@users.noreply.github.com> Date: Sat, 19 Sep 2026 11:50:37 +0530 Subject: [PATCH 62/70] feat(gin): add support for the HTTP QUERY method (RFC 10008) (#4806) * feat: add support for the HTTP QUERY method (RFC 10008) Add a QUERY shortcut on RouterGroup, a gin.MethodQuery constant and a gin.IQueryRoutes interface for callers that only hold an IRoutes value. QUERY is deliberately kept out of IRoutes and out of Any: - Adding a method to IRoutes would break every type outside of Gin that implements it, such as test doubles and wrappers. - Leaving Any untouched keeps existing catch-all routes matching exactly the methods they matched before. Match([]string{gin.MethodQuery, ...}) covers the case where QUERY is wanted alongside other methods. MethodQuery is declared in Gin because the standard library does not provide http.MethodQuery yet. The value stays correct once it does. Ref #4721 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(router): remove duplicate QUERY method - Consolidate QUERY into the existing router method after merging master - Preserve the MethodQuery constant and request body documentation --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Bo-Yi Wu --- docs/doc.md | 41 +++++++++++++++++++++++++++++++++ ginS/gins.go | 5 +++++ ginS/gins_test.go | 13 +++++++++++ routergroup.go | 38 +++++++++++++++++++++++++++---- routergroup_test.go | 4 ++++ routes_test.go | 55 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 152 insertions(+), 4 deletions(-) diff --git a/docs/doc.md b/docs/doc.md index d1c33b87..b635335e 100644 --- a/docs/doc.md +++ b/docs/doc.md @@ -7,6 +7,7 @@ - [Build without MsgPack rendering feature](#build-without-msgpack-rendering-feature) - [Routing](#routing) - [Using GET, POST, PUT, PATCH, DELETE and OPTIONS](#using-get-post-put-patch-delete-and-options) + - [Using the QUERY method](#using-the-query-method) - [Parameters in path](#parameters-in-path) - [Querystring parameters](#querystring-parameters) - [Multipart/Urlencoded Form](#multiparturlencoded-form) @@ -137,6 +138,46 @@ func main() { } ``` +### Using the QUERY method + +`QUERY` is the safe and idempotent method defined by [RFC 10008](https://www.rfc-editor.org/info/rfc10008/). It carries its query in the request body, so you can send a query that is too large or too structured for a URL without turning it into a `POST`. + +```go +func main() { + router := gin.Default() + + router.QUERY("/search", func(c *gin.Context) { + var query struct { + Term string `json:"term"` + } + if err := c.ShouldBindJSON(&query); err != nil { + c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + return + } + c.JSON(http.StatusOK, gin.H{"term": query.Term}) + }) + + router.Run() +} +``` + +Use the `gin.MethodQuery` constant wherever an HTTP method name is expected, for example when building a request in a test: + +```go +req := httptest.NewRequest(gin.MethodQuery, "/search", body) +``` + +Two things to keep in mind: + +- `router.Any` does not register `QUERY`, so existing catch-all routes keep matching exactly the methods they matched before. Use `router.QUERY` or `router.Match([]string{gin.MethodQuery, http.MethodPost}, ...)` when you want it. +- `QUERY` is not part of the `gin.IRoutes` interface. `*gin.Engine` and `*gin.RouterGroup` expose it directly; if you only hold an `IRoutes` value, assert to `gin.IQueryRoutes` first. + +```go +if q, ok := routes.(gin.IQueryRoutes); ok { + q.QUERY("/search", searching) +} +``` + ### Parameters in path ```go diff --git a/ginS/gins.go b/ginS/gins.go index 7918ce3a..5a82ab09 100644 --- a/ginS/gins.go +++ b/ginS/gins.go @@ -67,6 +67,11 @@ func GET(relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes { return engine().GET(relativePath, handlers...) } +// QUERY is a shortcut for router.Handle("QUERY", path, handle) +func QUERY(relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes { + return engine().QUERY(relativePath, handlers...) +} + // DELETE is a shortcut for router.Handle("DELETE", path, handle) func DELETE(relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes { return engine().DELETE(relativePath, handlers...) diff --git a/ginS/gins_test.go b/ginS/gins_test.go index ffde85d2..d7f0d624 100644 --- a/ginS/gins_test.go +++ b/ginS/gins_test.go @@ -31,6 +31,19 @@ func TestGET(t *testing.T) { assert.Equal(t, "test", w.Body.String()) } +func TestQUERY(t *testing.T) { + QUERY("/query", func(c *gin.Context) { + c.String(http.StatusOK, "query") + }) + + req := httptest.NewRequest(gin.MethodQuery, "/query", nil) + w := httptest.NewRecorder() + engine().ServeHTTP(w, req) + + assert.Equal(t, http.StatusOK, w.Code) + assert.Equal(t, "query", w.Body.String()) +} + func TestPOST(t *testing.T) { POST("/post", func(c *gin.Context) { c.String(http.StatusCreated, "created") diff --git a/routergroup.go b/routergroup.go index 84d3e00b..d85a8baf 100644 --- a/routergroup.go +++ b/routergroup.go @@ -11,6 +11,11 @@ import ( "strings" ) +// MethodQuery is the HTTP QUERY method defined by RFC 10008. It is declared +// here because the standard library does not provide http.MethodQuery yet. +// Once it does, this constant keeps the same value and stays valid. +const MethodQuery = "QUERY" + var ( // regEnLetter matches english letters for http method name regEnLetter = regexp.MustCompile("^[A-Z]+$") @@ -50,6 +55,22 @@ type IRoutes interface { StaticFS(string, http.FileSystem) IRoutes } +// IQueryRoutes defines the router handle interface for the HTTP QUERY method. +// +// It is deliberately kept out of IRoutes: adding a method to IRoutes would +// break every type outside of Gin that implements it, such as test doubles and +// wrappers. Type assert when you only hold an IRoutes value: +// +// if q, ok := routes.(gin.IQueryRoutes); ok { +// q.QUERY("/search", handler) +// } +// +// *gin.RouterGroup and *gin.Engine satisfy this interface, so the assertion is +// only needed when the concrete type has been erased. +type IQueryRoutes interface { + QUERY(string, ...HandlerFunc) IRoutes +} + // RouterGroup is used internally to configure router, a RouterGroup is associated with // a prefix and an array of handlers (middleware). type RouterGroup struct { @@ -59,7 +80,10 @@ type RouterGroup struct { root bool } -var _ IRouter = (*RouterGroup)(nil) +var ( + _ IRouter = (*RouterGroup)(nil) + _ IQueryRoutes = (*RouterGroup)(nil) +) // Use adds middleware to the group, see example code in GitHub. func (group *RouterGroup) Use(middleware ...HandlerFunc) IRoutes { @@ -145,14 +169,20 @@ func (group *RouterGroup) HEAD(relativePath string, handlers ...HandlerFunc) IRo } // QUERY is a shortcut for router.Handle("QUERY", path, handlers). -// The QUERY method is defined by RFC 10008 and is used to send a query -// in the request body, similar to GET but with a body. +// +// QUERY is the safe and idempotent method defined by RFC 10008 that carries its +// query in the request body. The body is read like any other body, for example +// with c.ShouldBindJSON. func (group *RouterGroup) QUERY(relativePath string, handlers ...HandlerFunc) IRoutes { - return group.handle("QUERY", relativePath, handlers) + return group.handle(MethodQuery, relativePath, handlers) } // Any registers a route that matches all the HTTP methods. // GET, POST, PUT, PATCH, HEAD, OPTIONS, DELETE, CONNECT, TRACE. +// +// QUERY is not part of that list, so that Any keeps registering exactly the +// same routes as before. Register it with QUERY, or with +// Match([]string{gin.MethodQuery, ...}, ...) to combine it with other methods. func (group *RouterGroup) Any(relativePath string, handlers ...HandlerFunc) IRoutes { for _, method := range anyMethods { group.handle(method, relativePath, handlers) diff --git a/routergroup_test.go b/routergroup_test.go index 182c5589..be5c7819 100644 --- a/routergroup_test.go +++ b/routergroup_test.go @@ -42,6 +42,7 @@ func TestRouterGroupBasicHandle(t *testing.T) { performRequestInGroup(t, http.MethodDelete) performRequestInGroup(t, http.MethodHead) performRequestInGroup(t, http.MethodOptions) + performRequestInGroup(t, MethodQuery) } func performRequestInGroup(t *testing.T, method string) { @@ -78,6 +79,9 @@ func performRequestInGroup(t *testing.T, method string) { case http.MethodOptions: v1.OPTIONS("/test", handler) login.OPTIONS("/test", handler) + case MethodQuery: + v1.QUERY("/test", handler) + login.QUERY("/test", handler) default: panic("unknown method") } diff --git a/routes_test.go b/routes_test.go index 1b7570b0..e9a89252 100644 --- a/routes_test.go +++ b/routes_test.go @@ -10,6 +10,7 @@ import ( "net/http/httptest" "os" "path/filepath" + "strings" "testing" "github.com/stretchr/testify/assert" @@ -86,6 +87,60 @@ func testRouteNotOK2(method string, t *testing.T) { assert.Equal(t, http.StatusMethodNotAllowed, w.Code) } +// TestRouteQuery tests that a QUERY route is invoked and can read the request +// body, which is the whole point of the method (RFC 10008). +func TestRouteQuery(t *testing.T) { + type search struct { + Term string `json:"term"` + } + + router := New() + router.QUERY("/search", func(c *Context) { + var body search + require.NoError(t, c.ShouldBindJSON(&body)) + c.String(http.StatusOK, body.Term) + }) + + req := httptest.NewRequest(MethodQuery, "/search", strings.NewReader(`{"term":"gin"}`)) + req.Header.Set("Content-Type", MIMEJSON) + w := httptest.NewRecorder() + router.ServeHTTP(w, req) + + assert.Equal(t, http.StatusOK, w.Code) + assert.Equal(t, "gin", w.Body.String()) +} + +// TestRouteQueryNotRegisteredByAny documents that Any does not register QUERY, +// so that existing Any routes keep matching exactly the methods they used to. +func TestRouteQueryNotRegisteredByAny(t *testing.T) { + router := New() + router.Any("/test", func(c *Context) { + c.Status(http.StatusOK) + }) + + w := PerformRequest(router, MethodQuery, "/test") + + assert.Equal(t, http.StatusNotFound, w.Code) +} + +// TestQueryRoutesInterface tests that a router reached through IRoutes can +// still register a QUERY route via the IQueryRoutes assertion. +func TestQueryRoutesInterface(t *testing.T) { + router := New() + + var routes IRoutes = router.Group("/v1") + queryRoutes, ok := routes.(IQueryRoutes) + require.True(t, ok) + + queryRoutes.QUERY("/search", func(c *Context) { + c.Status(http.StatusOK) + }) + + w := PerformRequest(router, MethodQuery, "/v1/search") + + assert.Equal(t, http.StatusOK, w.Code) +} + func TestRouterMethod(t *testing.T) { router := New() router.PUT("/hey2", func(c *Context) { From 8ad9f9cbeab45887327608f393bb614187e06099 Mon Sep 17 00:00:00 2001 From: Wahid Rizka Fathurrohman <58039870+wahidrizka@users.noreply.github.com> Date: Sat, 19 Sep 2026 13:21:21 +0700 Subject: [PATCH 63/70] docs: fix the graceful shutdown example (#4809) The example calls errors.Is but never imports errors, so copying it as written fails to build with "undefined: errors". It also passes an unbuffered channel to signal.Notify, which go vet reports as a misuse: signal delivery is non-blocking, so a signal that arrives before the receive is dropped. --- docs/doc.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/doc.md b/docs/doc.md index b635335e..3f0c94ea 100644 --- a/docs/doc.md +++ b/docs/doc.md @@ -2399,6 +2399,7 @@ package main import ( "context" + "errors" "log" "net/http" "os" @@ -2431,7 +2432,7 @@ func main() { // Wait for interrupt signal to gracefully shutdown the server with // a timeout of 5 seconds. - quit := make(chan os.Signal) + quit := make(chan os.Signal, 1) // kill (no param) default send syscall.SIGTERM // kill -2 is syscall.SIGINT // kill -9 is syscall.SIGKILL but can't be caught, so don't need to add it From d8f2d588d7573b3438cfc95b7a47f9ec8966273c Mon Sep 17 00:00:00 2001 From: Ruben Pari <73421813+RubenPari@users.noreply.github.com> Date: Sat, 19 Sep 2026 08:41:53 +0200 Subject: [PATCH 64/70] fix(engine): add default ReadHeaderTimeout to http.Server in Run methods (#4800) Engine.Run, RunTLS, and RunListener created an http.Server without ReadHeaderTimeout, leaving applications exposed to slowloris-style resource exhaustion. A new Engine.ReadHeaderTimeout field (default 10s) is now applied to the http.Server created by these methods. Users can customize the value or use a custom http.Server for full control. Fixes #4760 Co-authored-by: Bo-Yi Wu --- gin.go | 39 ++++++++++++++++++++++++++++++++++----- gin_test.go | 20 ++++++++++++++++++++ 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/gin.go b/gin.go index 2e033bf3..a1607275 100644 --- a/gin.go +++ b/gin.go @@ -13,6 +13,7 @@ import ( "path" "strings" "sync" + "time" "github.com/gin-gonic/gin/internal/bytesconv" filesystem "github.com/gin-gonic/gin/internal/fs" @@ -29,6 +30,12 @@ const ( backslash = "\\" ) +// defaultReadHeaderTimeout is the default ReadHeaderTimeout applied to the +// http.Server created by Run, RunTLS and RunListener. It protects against +// slowloris-style resource exhaustion when the caller does not configure a +// custom http.Server. +const defaultReadHeaderTimeout = 10 * time.Second + var ( default404Body = []byte("404 page not found") default405Body = []byte("405 method not allowed") @@ -166,6 +173,12 @@ type Engine struct { // method call. MaxMultipartMemory int64 + // ReadHeaderTimeout is the maximum duration allowed for reading the request + // headers by the http.Server created through Run, RunTLS and RunListener. + // If zero or negative, a default of 10 seconds is used. Set to a positive + // value to customize, or use a custom http.Server directly to disable it. + ReadHeaderTimeout time.Duration + // UseH2C enable h2c support. UseH2C bool @@ -219,6 +232,7 @@ func New(opts ...OptionFunc) *Engine { RemoveExtraSlash: false, UnescapePathValues: true, MaxMultipartMemory: defaultMultipartMemory, + ReadHeaderTimeout: defaultReadHeaderTimeout, trees: make(methodTrees, 0, 9), delims: render.Delims{Left: "{{", Right: "}}"}, secureJSONPrefix: "while(1);", @@ -255,6 +269,15 @@ func (engine *Engine) allocateContext(maxParams uint16) *Context { return &Context{engine: engine, params: &v, skippedNodes: &skippedNodes} } +// getReadHeaderTimeout returns the configured ReadHeaderTimeout, or the +// default if it is zero or negative. +func (engine *Engine) getReadHeaderTimeout() time.Duration { + if engine.ReadHeaderTimeout <= 0 { + return defaultReadHeaderTimeout + } + return engine.ReadHeaderTimeout +} + // Delims sets template left and right delims and returns an Engine instance. func (engine *Engine) Delims(left, right string) *Engine { engine.delims = render.Delims{Left: left, Right: right} @@ -537,6 +560,9 @@ func parseIP(ip string) net.IP { // Run attaches the router to a http.Server and starts listening and serving HTTP requests. // It is a shortcut for http.ListenAndServe(addr, router) // Note: this method will block the calling goroutine indefinitely unless an error happens. +// The created http.Server is configured with a default ReadHeaderTimeout of 10 seconds +// (configurable via Engine.ReadHeaderTimeout) to mitigate slowloris attacks. +// For full control over timeouts, create a custom http.Server and use ServeHTTP. func (engine *Engine) Run(addr ...string) (err error) { defer func() { debugPrintError(err) }() @@ -548,8 +574,9 @@ func (engine *Engine) Run(addr ...string) (err error) { address := resolveAddress(addr) debugPrint("Listening and serving HTTP on %s\n", address) server := &http.Server{ // #nosec G112 - Addr: address, - Handler: engine.Handler(), + Addr: address, + Handler: engine.Handler(), + ReadHeaderTimeout: engine.getReadHeaderTimeout(), } err = server.ListenAndServe() return @@ -568,8 +595,9 @@ func (engine *Engine) RunTLS(addr, certFile, keyFile string) (err error) { } server := &http.Server{ // #nosec G112 - Addr: addr, - Handler: engine.Handler(), + Addr: addr, + Handler: engine.Handler(), + ReadHeaderTimeout: engine.getReadHeaderTimeout(), } err = server.ListenAndServeTLS(certFile, keyFile) return @@ -652,7 +680,8 @@ func (engine *Engine) RunListener(listener net.Listener) (err error) { } server := &http.Server{ // #nosec G112 - Handler: engine.Handler(), + Handler: engine.Handler(), + ReadHeaderTimeout: engine.getReadHeaderTimeout(), } err = server.Serve(listener) return diff --git a/gin_test.go b/gin_test.go index b488c446..71a817a7 100644 --- a/gin_test.go +++ b/gin_test.go @@ -1024,6 +1024,26 @@ func TestWithOptionFunc(t *testing.T) { assertRoutePresent(t, routes, RouteInfo{Path: "/test2", Method: http.MethodGet, Handler: "github.com/gin-gonic/gin.handlerTest2"}) } +func TestReadHeaderTimeoutDefault(t *testing.T) { + engine := New() + assert.Equal(t, defaultReadHeaderTimeout, engine.ReadHeaderTimeout) + assert.Equal(t, defaultReadHeaderTimeout, engine.getReadHeaderTimeout()) +} + +func TestReadHeaderTimeoutCustom(t *testing.T) { + engine := New(func(e *Engine) { + e.ReadHeaderTimeout = 30 * time.Second + }) + assert.Equal(t, 30*time.Second, engine.ReadHeaderTimeout) + assert.Equal(t, 30*time.Second, engine.getReadHeaderTimeout()) +} + +func TestReadHeaderTimeoutZeroFallsBackToDefault(t *testing.T) { + engine := New() + engine.ReadHeaderTimeout = 0 + assert.Equal(t, defaultReadHeaderTimeout, engine.getReadHeaderTimeout()) +} + type Birthday string func (b *Birthday) UnmarshalParam(param string) error { From 3b08cd7235bd5ad2f055aa9e38135f111f6c5926 Mon Sep 17 00:00:00 2001 From: water <672684719@qq.com> Date: Sat, 19 Sep 2026 21:11:32 +0800 Subject: [PATCH 65/70] fix: reset skipped-nodes stack on getValue entry to prevent slice overflow panic [#4818] (#4819) * fix: reset skipped-nodes stack on getValue entry to prevent slice overflow panic [#4818] * test: add regression test for getValue skipped-nodes overflow panic [#4818] * test(gin): consolidate routing regression tests - Move skipped-node regression cases into the existing routing test suite without changing behavior. --------- Co-authored-by: Bo-Yi Wu --- routes_test.go | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++ tree.go | 8 +++++ 2 files changed, 105 insertions(+) diff --git a/routes_test.go b/routes_test.go index e9a89252..dbfaad5c 100644 --- a/routes_test.go +++ b/routes_test.go @@ -844,3 +844,100 @@ func TestEngineHandleMethodNotAllowedCornerCase(t *testing.T) { w := PerformRequest(r, http.MethodGet, "/base/v1/user/groups") assert.Equal(t, http.StatusNotFound, w.Code) } + +// TestIssue4818_skippedNodesOverflow_Panic reproduces the panic from issue #4818: +// with HandleMethodNotAllowed enabled, getValue is called once per method tree +// reusing the same c.skippedNodes stack without resetting it, so residue +// accumulates until the reslice exceeds the capacity (engine.maxSections). +// The request must not panic and must fall through to the normal 404 path +// (the path genuinely matches no route, so 405 is not applicable here). +func TestIssue4818_skippedNodesOverflow_Panic(t *testing.T) { + router := New() + router.HandleMethodNotAllowed = true + + h := func(c *Context) {} + router.OPTIONS("/:p0/:p1/a/:p2", h) + router.GET("/:p0/:p1/a/:p2", h) + router.PATCH("/b/:p0/:p1/c", h) + router.DELETE("/b/:p0/:p1/d/:p3", h) + router.GET("/b/:p0/:p1/e/f", h) + router.POST("/b/:p0/:p1/g/:p4/h", h) + router.OPTIONS("/b/:p0/:p1/g/:p4/h", h) + router.DELETE("/b/cache", h) + router.GET("/b/clients/:p1/g", h) + router.POST("/b/clients/:p1/g", h) + router.PATCH("/b/clients/:p1/g/:p4", h) + router.OPTIONS("/b/clients/:p1/g/:p4", h) + + req := httptest.NewRequest(http.MethodPost, "/b/clients/42", nil) + w := httptest.NewRecorder() + router.ServeHTTP(w, req) + + // Must not panic; path matches no route, so 404 is the correct outcome. + if w.Code != http.StatusNotFound { + t.Fatalf("expected 404, got %d (a panic would have aborted the test)", w.Code) + } +} + +// TestIssue4818_MethodNotAllowedStillWorks verifies the HandleMethodNotAllowed +// loop still produces a correct 405 with an Allow header after the fix, i.e. +// the reset does not break the loop across multiple method trees. +func TestIssue4818_MethodNotAllowedStillWorks(t *testing.T) { + router := New() + router.HandleMethodNotAllowed = true + + h := func(c *Context) {} + router.OPTIONS("/:p0/:p1/a/:p2", h) + router.GET("/:p0/:p1/a/:p2", h) + router.PATCH("/b/:p0/:p1/c", h) + router.DELETE("/b/:p0/:p1/d/:p3", h) + router.GET("/b/:p0/:p1/e/f", h) + router.POST("/b/:p0/:p1/g/:p4/h", h) + router.OPTIONS("/b/:p0/:p1/g/:p4/h", h) + router.DELETE("/b/cache", h) + router.GET("/b/clients/:p1/g", h) + router.POST("/b/clients/:p1/g", h) + router.PATCH("/b/clients/:p1/g/:p4", h) + router.OPTIONS("/b/clients/:p1/g/:p4", h) + + // PATCH /b/clients/42/g is registered under GET but not under PATCH + // -> HandleMethodNotAllowed should yield 405 with an Allow header. + req := httptest.NewRequest(http.MethodPatch, "/b/clients/42/g", nil) + w := httptest.NewRecorder() + router.ServeHTTP(w, req) + + if w.Code != http.StatusMethodNotAllowed { + t.Fatalf("expected 405, got %d", w.Code) + } + allow := w.Header().Get("Allow") + if allow == "" { + t.Fatal("expected Allow header to be set for 405") + } +} + +// TestIssue4818_MethodNotAllowedManyTrees stresses the loop across many +// method trees to make sure the skipped-nodes accumulator can never overflow. +func TestIssue4818_MethodNotAllowedManyTrees(t *testing.T) { + router := New() + router.HandleMethodNotAllowed = true + + h := func(c *Context) {} + for _, m := range []string{ + http.MethodGet, http.MethodPost, http.MethodPut, http.MethodDelete, + http.MethodPatch, http.MethodOptions, http.MethodHead, http.MethodConnect, + http.MethodTrace, + } { + router.Handle(m, "/:p0/:p1/a/:p2", h) + router.Handle(m, "/s/:p0/:p1/:p2/:p3/:p4/:p5/d", h) + } + // GET route so that a POST to a GET-only path yields 405 + router.GET("/only-get", h) + + req := httptest.NewRequest(http.MethodPost, "/only-get", nil) + w := httptest.NewRecorder() + router.ServeHTTP(w, req) + + if w.Code != http.StatusMethodNotAllowed { + t.Fatalf("expected 405, got %d", w.Code) + } +} diff --git a/tree.go b/tree.go index dc84ff61..6efe2e0e 100644 --- a/tree.go +++ b/tree.go @@ -418,6 +418,14 @@ type skippedNode struct { func (n *node) getValue(path string, params *Params, skippedNodes *[]skippedNode, unescape bool) (value nodeValue) { var globalParamsCount int16 + // Reset the skipped-nodes stack on entry. getValue is called once per + // method tree (e.g. in the HandleMethodNotAllowed loop) reusing the same + // pooled Context stack, and the walk below grows it via a raw reslice that + // cannot exceed engine.maxSections. Without this reset the residue from a + // previous tree leaks into the next call and can panic with "slice bounds + // out of range" once the accumulated length passes the capacity. + *skippedNodes = (*skippedNodes)[:0] + walk: // Outer loop for walking the tree for { prefix := n.path From 1bd0ecf2d3e08da37efa270bb7be20c1eddb0d68 Mon Sep 17 00:00:00 2001 From: HazyLab Date: Fri, 25 Sep 2026 08:01:37 +0200 Subject: [PATCH 66/70] fix(context): load Keys under the mutex in Copy (#4854) Copy read c.Keys before RLock. Set stores that field under Lock when the map is created. The race detector reports the unsynchronized access, and the copy can observe a nil header and drop keys Set has already published. maps.Clone(nil) returns nil, so the load and the clone belong in the same critical section. Map iteration was already under the mutex. Co-authored-by: hazyhaar --- context.go | 3 +-- context_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/context.go b/context.go index 788b00bb..a6add8a6 100644 --- a/context.go +++ b/context.go @@ -132,9 +132,8 @@ func (c *Context) Copy() *Context { cp.handlers = nil cp.fullPath = c.fullPath - cKeys := c.Keys c.mu.RLock() - cp.Keys = maps.Clone(cKeys) + cp.Keys = maps.Clone(c.Keys) c.mu.RUnlock() cParams := c.Params diff --git a/context_test.go b/context_test.go index cef488c9..b82e04d5 100644 --- a/context_test.go +++ b/context_test.go @@ -709,6 +709,30 @@ func TestContextGetStringMapStringSlice(t *testing.T) { assert.Equal(t, []string{"foo"}, c.GetStringMapStringSlice("map")["foo"]) } +func TestCopyConcurrentWithSet(t *testing.T) { + c := &Context{} + var wg sync.WaitGroup + wg.Add(2) + go func() { + defer wg.Done() + for i := 0; i < 100; i++ { + c.Set(i, i) + } + }() + go func() { + defer wg.Done() + for i := 0; i < 100; i++ { + cp := c.Copy() + for k, v := range cp.Keys { + if k != v { + t.Errorf("copied key %v = %v, want %v", k, v, k) + } + } + } + }() + wg.Wait() +} + func TestContextCopy(t *testing.T) { c, _ := CreateTestContext(httptest.NewRecorder()) c.index = 2 From 43fe48e8a0f44af783116cdb010725e6bb50255f Mon Sep 17 00:00:00 2001 From: Zain Qureshi <43629888+ZainnQureshii@users.noreply.github.com> Date: Tue, 29 Sep 2026 15:14:45 +0200 Subject: [PATCH 67/70] docs: fix SecureJSON default prefix and default-binding example output (#4861) The SecureJSON docs and the Context.SecureJSON comment said the default prefix is "while(1),". The engine sets secureJSONPrefix to "while(1);" (gin.go), and the example output a few lines below already shows the semicolon. The default-values binding example printed a "Colors" field that the Person struct does not have; the struct's array field is Addresses with default "foo bar", which binds to ["foo","bar"]. Co-authored-by: Claude Opus 5.5 --- context.go | 2 +- docs/doc.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/context.go b/context.go index a6add8a6..582d00f2 100644 --- a/context.go +++ b/context.go @@ -1236,7 +1236,7 @@ func (c *Context) IndentedJSON(code int, obj any) { } // SecureJSON serializes the given struct as Secure JSON into the response body. -// Default prepends "while(1)," to response body if the given struct is array values. +// Default prepends "while(1);" to response body if the given struct is array values. // It also sets the Content-Type as "application/json". func (c *Context) SecureJSON(code int, obj any) { c.Render(code, render.SecureJSON{Prefix: c.engine.secureJSONPrefix, Data: obj}) diff --git a/docs/doc.md b/docs/doc.md index 3f0c94ea..16102841 100644 --- a/docs/doc.md +++ b/docs/doc.md @@ -1167,7 +1167,7 @@ func main() { ```sh curl -X POST http://localhost:8080/person -{"Name":"William","Age":10,"Friends":["Will","Bill"],"Colors":["red","blue"],"LapTimes":[1,2,3]} +{"Name":"William","Age":10,"Friends":["Will","Bill"],"Addresses":["foo","bar"],"LapTimes":[1,2,3]} ``` NOTE: For default [collection values](#collection-format-for-arrays), the following rules apply: @@ -1762,7 +1762,7 @@ func main() { #### SecureJSON -Using SecureJSON to prevent json hijacking. Default prepends `"while(1),"` to response body if the given struct is array values. +Using SecureJSON to prevent json hijacking. Default prepends `"while(1);"` to response body if the given struct is array values. ```go func main() { From e8f24969d59611428b03d02424b8f4bb55a1ef91 Mon Sep 17 00:00:00 2001 From: adam magued Date: Sat, 10 Oct 2026 07:16:17 +0300 Subject: [PATCH 68/70] feat(routergroup): include HTTP QUERY method in Any (#4878) Signed-off-by: AdamMagued --- docs/doc.md | 3 +-- routergroup.go | 8 ++------ routergroup_test.go | 22 ++++++++++++++++++++++ routes_test.go | 10 ++++++---- 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/docs/doc.md b/docs/doc.md index 16102841..366b249b 100644 --- a/docs/doc.md +++ b/docs/doc.md @@ -167,9 +167,8 @@ Use the `gin.MethodQuery` constant wherever an HTTP method name is expected, for req := httptest.NewRequest(gin.MethodQuery, "/search", body) ``` -Two things to keep in mind: +Keep in mind: -- `router.Any` does not register `QUERY`, so existing catch-all routes keep matching exactly the methods they matched before. Use `router.QUERY` or `router.Match([]string{gin.MethodQuery, http.MethodPost}, ...)` when you want it. - `QUERY` is not part of the `gin.IRoutes` interface. `*gin.Engine` and `*gin.RouterGroup` expose it directly; if you only hold an `IRoutes` value, assert to `gin.IQueryRoutes` first. ```go diff --git a/routergroup.go b/routergroup.go index d85a8baf..47eeee58 100644 --- a/routergroup.go +++ b/routergroup.go @@ -24,7 +24,7 @@ var ( anyMethods = []string{ http.MethodGet, http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodHead, http.MethodOptions, http.MethodDelete, http.MethodConnect, - http.MethodTrace, + http.MethodTrace, MethodQuery, } ) @@ -178,11 +178,7 @@ func (group *RouterGroup) QUERY(relativePath string, handlers ...HandlerFunc) IR } // Any registers a route that matches all the HTTP methods. -// GET, POST, PUT, PATCH, HEAD, OPTIONS, DELETE, CONNECT, TRACE. -// -// QUERY is not part of that list, so that Any keeps registering exactly the -// same routes as before. Register it with QUERY, or with -// Match([]string{gin.MethodQuery, ...}, ...) to combine it with other methods. +// GET, POST, PUT, PATCH, HEAD, OPTIONS, DELETE, CONNECT, TRACE, QUERY. func (group *RouterGroup) Any(relativePath string, handlers ...HandlerFunc) IRoutes { for _, method := range anyMethods { group.handle(method, relativePath, handlers) diff --git a/routergroup_test.go b/routergroup_test.go index be5c7819..c3859a35 100644 --- a/routergroup_test.go +++ b/routergroup_test.go @@ -221,3 +221,25 @@ func TestRouterGroupCombineHandlersEmptySliceNotNil(t *testing.T) { assert.NotNil(t, result, "result should not be nil even with empty handlers") assert.Empty(t, result, "empty handlers should return empty chain") } + +func TestRouterGroupAny(t *testing.T) { + router := New() + router.Any("/any", func(c *Context) { + c.String(http.StatusOK, c.Request.Method) + }) + + v1 := router.Group("/v1") + v1.Any("/any", func(c *Context) { + c.String(http.StatusOK, "v1:"+c.Request.Method) + }) + + for _, method := range anyMethods { + w := PerformRequest(router, method, "/any") + assert.Equal(t, http.StatusOK, w.Code) + assert.Equal(t, method, w.Body.String()) + + w = PerformRequest(router, method, "/v1/any") + assert.Equal(t, http.StatusOK, w.Code) + assert.Equal(t, "v1:"+method, w.Body.String()) + } +} diff --git a/routes_test.go b/routes_test.go index dbfaad5c..3306233f 100644 --- a/routes_test.go +++ b/routes_test.go @@ -110,9 +110,8 @@ func TestRouteQuery(t *testing.T) { assert.Equal(t, "gin", w.Body.String()) } -// TestRouteQueryNotRegisteredByAny documents that Any does not register QUERY, -// so that existing Any routes keep matching exactly the methods they used to. -func TestRouteQueryNotRegisteredByAny(t *testing.T) { +// TestRouteQueryRegisteredByAny documents that Any registers QUERY. +func TestRouteQueryRegisteredByAny(t *testing.T) { router := New() router.Any("/test", func(c *Context) { c.Status(http.StatusOK) @@ -120,7 +119,7 @@ func TestRouteQueryNotRegisteredByAny(t *testing.T) { w := PerformRequest(router, MethodQuery, "/test") - assert.Equal(t, http.StatusNotFound, w.Code) + assert.Equal(t, http.StatusOK, w.Code) } // TestQueryRoutesInterface tests that a router reached through IRoutes can @@ -171,6 +170,7 @@ func TestRouterGroupRouteOK(t *testing.T) { testRouteOK(http.MethodDelete, t) testRouteOK(http.MethodConnect, t) testRouteOK(http.MethodTrace, t) + testRouteOK(MethodQuery, t) } func TestRouteNotOK(t *testing.T) { @@ -183,6 +183,7 @@ func TestRouteNotOK(t *testing.T) { testRouteNotOK(http.MethodDelete, t) testRouteNotOK(http.MethodConnect, t) testRouteNotOK(http.MethodTrace, t) + testRouteNotOK(MethodQuery, t) } func TestRouteNotOK2(t *testing.T) { @@ -195,6 +196,7 @@ func TestRouteNotOK2(t *testing.T) { testRouteNotOK2(http.MethodDelete, t) testRouteNotOK2(http.MethodConnect, t) testRouteNotOK2(http.MethodTrace, t) + testRouteNotOK2(MethodQuery, t) } func TestRouteRedirectTrailingSlash(t *testing.T) { From ea9fab99e01d55a5e4f8daacc0d11ccffaee0a15 Mon Sep 17 00:00:00 2001 From: HazyLab Date: Sat, 10 Oct 2026 06:18:54 +0200 Subject: [PATCH 69/70] fix(tree): grow skippedNodes when pooled capacity is stale (#4852) getValue resliced the backtrack stack to index+1 on the assumption that its capacity equals Engine.maxSections. The pool captures that capacity at allocation. Routes registered afterwards raise maxSections without resizing the pooled slice. The next request that needs one more frame panics inside the router, before Recovery. append grows the slice when the captured capacity is short and preserves the existing backtrack behaviour when it is already sufficient. The reset at entry stays: getValue still runs once per method tree on the same stack. Co-authored-by: hazyhaar Co-authored-by: Bo-Yi Wu --- routes_test.go | 24 ++++++++++++++++++++++++ tree.go | 15 +++++++-------- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/routes_test.go b/routes_test.go index 3306233f..a032a2b7 100644 --- a/routes_test.go +++ b/routes_test.go @@ -847,6 +847,30 @@ func TestEngineHandleMethodNotAllowedCornerCase(t *testing.T) { assert.Equal(t, http.StatusNotFound, w.Code) } +func TestLateRouteRegistrationSkippedNodes(t *testing.T) { + router := New() + router.HandleMethodNotAllowed = true + router.GET("/a", func(c *Context) { c.Status(http.StatusOK) }) + + w := PerformRequest(router, http.MethodGet, "/a") + if w.Code != http.StatusOK { + t.Fatalf("warmup status = %d, want 200", w.Code) + } + + h := func(c *Context) {} + router.GET("/x/y/z/w", h) + router.GET("/x/y/:id/w", h) + router.GET("/x/:id/z/w", h) + router.GET("/:id/y/z/w", h) + + req := httptest.NewRequest(http.MethodPost, "/x/y/z/w/extra", nil) + w = httptest.NewRecorder() + router.ServeHTTP(w, req) + if w.Code != http.StatusNotFound { + t.Fatalf("status = %d, want 404", w.Code) + } +} + // TestIssue4818_skippedNodesOverflow_Panic reproduces the panic from issue #4818: // with HandleMethodNotAllowed enabled, getValue is called once per method tree // reusing the same c.skippedNodes stack without resetting it, so residue diff --git a/tree.go b/tree.go index 6efe2e0e..6842d225 100644 --- a/tree.go +++ b/tree.go @@ -420,10 +420,11 @@ func (n *node) getValue(path string, params *Params, skippedNodes *[]skippedNode // Reset the skipped-nodes stack on entry. getValue is called once per // method tree (e.g. in the HandleMethodNotAllowed loop) reusing the same - // pooled Context stack, and the walk below grows it via a raw reslice that - // cannot exceed engine.maxSections. Without this reset the residue from a - // previous tree leaks into the next call and can panic with "slice bounds - // out of range" once the accumulated length passes the capacity. + // pooled Context stack. Without this reset the residue from a previous + // tree leaks into the next call. The walk grows the stack with append: + // a context allocated before addRoute raised maxSections must still be + // able to record one more backtrack frame. A raw reslice of the capacity + // captured at pool allocation panics with "slice bounds out of range". *skippedNodes = (*skippedNodes)[:0] walk: // Outer loop for walking the tree @@ -439,9 +440,7 @@ walk: // Outer loop for walking the tree if c == idxc { // strings.HasPrefix(n.children[len(n.children)-1].path, ":") == n.wildChild if n.wildChild { - index := len(*skippedNodes) - *skippedNodes = (*skippedNodes)[:index+1] - (*skippedNodes)[index] = skippedNode{ + *skippedNodes = append(*skippedNodes, skippedNode{ path: prefix + path, node: &node{ path: n.path, @@ -453,7 +452,7 @@ walk: // Outer loop for walking the tree fullPath: n.fullPath, }, paramsCount: globalParamsCount, - } + }) } n = n.children[i] From 0f09c3a9b4626d9fe9979cf4d0521d6ae32ab646 Mon Sep 17 00:00:00 2001 From: Little Fedya Date: Sat, 10 Oct 2026 09:20:35 +0500 Subject: [PATCH 70/70] docs: include HTTP QUERY method in RouterGroup.Any (#4879) Co-authored-by: Bo-Yi Wu --- docs/doc.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/doc.md b/docs/doc.md index 366b249b..01edf52c 100644 --- a/docs/doc.md +++ b/docs/doc.md @@ -169,6 +169,7 @@ req := httptest.NewRequest(gin.MethodQuery, "/search", body) Keep in mind: +- `router.Any` also registers `QUERY` alongside standard HTTP methods. Handlers registered with `Any` should respect QUERY's safe and idempotent semantics when processing that method. - `QUERY` is not part of the `gin.IRoutes` interface. `*gin.Engine` and `*gin.RouterGroup` expose it directly; if you only hold an `IRoutes` value, assert to `gin.IQueryRoutes` first. ```go