From 7e4ed972742342c535f3c738104523e7ffd2e75e Mon Sep 17 00:00:00 2001 From: Kuroda Kayn Date: Sun, 15 Nov 2026 21:55:43 +0800 Subject: [PATCH] chore(go): adopt http.MethodQuery for QUERY routes --- .github/workflows/gin.yml | 2 +- README.md | 2 +- docs/doc.md | 4 ++-- ginS/gins_test.go | 2 +- go.mod | 2 +- routergroup.go | 11 +++++------ routergroup_test.go | 4 ++-- routes_test.go | 12 ++++++------ 8 files changed, 19 insertions(+), 20 deletions(-) diff --git a/.github/workflows/gin.yml b/.github/workflows/gin.yml index d0f42d09..7171861f 100644 --- a/.github/workflows/gin.yml +++ b/.github/workflows/gin.yml @@ -36,7 +36,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest] - go: ["1.26", "1.27"] + go: ["1.28"] test-tags: [ "", diff --git a/README.md b/README.md index 10e627fc..79a60f1f 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.26](https://go.dev/doc/devel/release#go1.26.0) or above +- **Go version**: Gin requires [Go](https://go.dev/) version [1.28](https://go.dev/doc/devel/release#go1.28.0) or above - **Basic Go knowledge**: Familiarity with Go syntax and package management is helpful ### Installation diff --git a/docs/doc.md b/docs/doc.md index 01edf52c..28c1edbe 100644 --- a/docs/doc.md +++ b/docs/doc.md @@ -161,10 +161,10 @@ func main() { } ``` -Use the `gin.MethodQuery` constant wherever an HTTP method name is expected, for example when building a request in a test: +Use Go's `http.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) +req := httptest.NewRequest(http.MethodQuery, "/search", body) ``` Keep in mind: diff --git a/ginS/gins_test.go b/ginS/gins_test.go index d7f0d624..e8b9552c 100644 --- a/ginS/gins_test.go +++ b/ginS/gins_test.go @@ -36,7 +36,7 @@ func TestQUERY(t *testing.T) { c.String(http.StatusOK, "query") }) - req := httptest.NewRequest(gin.MethodQuery, "/query", nil) + req := httptest.NewRequest(http.MethodQuery, "/query", nil) w := httptest.NewRecorder() engine().ServeHTTP(w, req) diff --git a/go.mod b/go.mod index 99a8d5bb..5d5171a8 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/gin-gonic/gin -go 1.26.0 +go 1.28.0 require ( github.com/bytedance/sonic v1.15.0 diff --git a/routergroup.go b/routergroup.go index 47eeee58..5de4ff9b 100644 --- a/routergroup.go +++ b/routergroup.go @@ -11,10 +11,9 @@ 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" +// MethodQuery aliases the HTTP QUERY method defined by RFC 10008. +// Deprecated: use http.MethodQuery instead. +const MethodQuery = http.MethodQuery var ( // regEnLetter matches english letters for http method name @@ -24,7 +23,7 @@ var ( anyMethods = []string{ http.MethodGet, http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodHead, http.MethodOptions, http.MethodDelete, http.MethodConnect, - http.MethodTrace, MethodQuery, + http.MethodTrace, http.MethodQuery, } ) @@ -174,7 +173,7 @@ func (group *RouterGroup) HEAD(relativePath string, handlers ...HandlerFunc) IRo // 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(MethodQuery, relativePath, handlers) + return group.handle(http.MethodQuery, relativePath, handlers) } // Any registers a route that matches all the HTTP methods. diff --git a/routergroup_test.go b/routergroup_test.go index c3859a35..96f78f4a 100644 --- a/routergroup_test.go +++ b/routergroup_test.go @@ -42,7 +42,7 @@ func TestRouterGroupBasicHandle(t *testing.T) { performRequestInGroup(t, http.MethodDelete) performRequestInGroup(t, http.MethodHead) performRequestInGroup(t, http.MethodOptions) - performRequestInGroup(t, MethodQuery) + performRequestInGroup(t, http.MethodQuery) } func performRequestInGroup(t *testing.T, method string) { @@ -79,7 +79,7 @@ func performRequestInGroup(t *testing.T, method string) { case http.MethodOptions: v1.OPTIONS("/test", handler) login.OPTIONS("/test", handler) - case MethodQuery: + case http.MethodQuery: v1.QUERY("/test", handler) login.QUERY("/test", handler) default: diff --git a/routes_test.go b/routes_test.go index a032a2b7..8b07573f 100644 --- a/routes_test.go +++ b/routes_test.go @@ -101,7 +101,7 @@ func TestRouteQuery(t *testing.T) { c.String(http.StatusOK, body.Term) }) - req := httptest.NewRequest(MethodQuery, "/search", strings.NewReader(`{"term":"gin"}`)) + req := httptest.NewRequest(http.MethodQuery, "/search", strings.NewReader(`{"term":"gin"}`)) req.Header.Set("Content-Type", MIMEJSON) w := httptest.NewRecorder() router.ServeHTTP(w, req) @@ -117,7 +117,7 @@ func TestRouteQueryRegisteredByAny(t *testing.T) { c.Status(http.StatusOK) }) - w := PerformRequest(router, MethodQuery, "/test") + w := PerformRequest(router, http.MethodQuery, "/test") assert.Equal(t, http.StatusOK, w.Code) } @@ -135,7 +135,7 @@ func TestQueryRoutesInterface(t *testing.T) { c.Status(http.StatusOK) }) - w := PerformRequest(router, MethodQuery, "/v1/search") + w := PerformRequest(router, http.MethodQuery, "/v1/search") assert.Equal(t, http.StatusOK, w.Code) } @@ -170,7 +170,7 @@ func TestRouterGroupRouteOK(t *testing.T) { testRouteOK(http.MethodDelete, t) testRouteOK(http.MethodConnect, t) testRouteOK(http.MethodTrace, t) - testRouteOK(MethodQuery, t) + testRouteOK(http.MethodQuery, t) } func TestRouteNotOK(t *testing.T) { @@ -183,7 +183,7 @@ func TestRouteNotOK(t *testing.T) { testRouteNotOK(http.MethodDelete, t) testRouteNotOK(http.MethodConnect, t) testRouteNotOK(http.MethodTrace, t) - testRouteNotOK(MethodQuery, t) + testRouteNotOK(http.MethodQuery, t) } func TestRouteNotOK2(t *testing.T) { @@ -196,7 +196,7 @@ func TestRouteNotOK2(t *testing.T) { testRouteNotOK2(http.MethodDelete, t) testRouteNotOK2(http.MethodConnect, t) testRouteNotOK2(http.MethodTrace, t) - testRouteNotOK2(MethodQuery, t) + testRouteNotOK2(http.MethodQuery, t) } func TestRouteRedirectTrailingSlash(t *testing.T) {