Each of these was checked by running the example against the current
master branch with net/http/httptest.
- Parameters in path: the comment said routes starting with /user/groups
are never interpreted as /user/:name/... routes. GET /user/groups/admin
is served by /user/:name/*action with name "groups". Only the exact
path /user/groups goes to the static route.
- Map as querystring or postform parameters: fmt prints map keys in
sorted order, so the output is map[a:1234 b:hello] and
map[first:thinkerou second:tianou].
- JSONP: the response body is x({"foo":"bar"}); with plain quotes and a
trailing semicolon. The escaped quotes were copied from a Go string
literal in the tests.
- Model binding: when Bind fails, AbortWithError(400, err) sends the
headers with an empty body and no Content-Type. It does not set
text/plain; charset=utf-8.
- Set and get a cookie: the first example used SetCookieData and
http.Cookie without importing net/http and time, so it did not
compile, and it duplicated the SetCookieData example that follows it.
Restore the SetCookie call it used before SetCookieData was added.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NQDmA3mwGfL83pbg9WQ6ey
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 <noreply@anthropic.com>
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.
* 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 <appleboy.tw@gmail.com>
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 <noreply@anthropic.com>
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 <appleboy.tw@gmail.com>
* feat(form): add array collection format in form binding
* feat(form): add array collection format in form binding
* test(form): fix test code for array collection format in form binding
* feat: ShouldBindBodyWith shortcut and change doc
* fix: yaml can parse json test case
* style: fix new test case in context_test.go
* chore: modify the code style to specify binding type
* chroe: gofmt modifies the code format