Merge 7e4ed972742342c535f3c738104523e7ffd2e75e into 0f09c3a9b4626d9fe9979cf4d0521d6ae32ab646

This commit is contained in:
Kuroda Kayn 2026-11-15 21:59:26 +08:00 committed by GitHub
commit 1af9eed6ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 19 additions and 20 deletions

View File

@ -36,7 +36,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
go: ["1.26", "1.27"]
go: ["1.28"]
test-tags:
[
"",

View File

@ -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

View File

@ -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:

View File

@ -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)

2
go.mod
View File

@ -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

View File

@ -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.

View File

@ -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:

View File

@ -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) {