69 Commits

Author SHA1 Message Date
Kuroda Kayn
ddf82d7611 feat(router): support AIP custom verb paths
Google AIP-style APIs use literal colon suffixes for custom methods, which Gin previously parsed as wildcard parameters.

Treat literal segment colons as static text and split param nodes before static suffix children such as :mutate.

This lets custom verb routes coexist with regular parameter routes while preserving escaped-colon behavior.
2026-06-28 16:10:40 +08:00
Varun Chawla
472d086af2
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 <appleboy.tw@gmail.com>
2026-02-28 11:15:27 +08:00
Artur Melanchyk
cad29c5e3f
perf(tree): reduce allocations in findCaseInsensitivePath (#4417)
Co-authored-by: Artur Melanchyk <13834276+arturmelanchyk@users.noreply.github.com>
2026-01-25 00:46:02 +08:00
OHZEKI Naoki
d1a15347b1
refactor(utils): move util functions to utils.go (#4467)
Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2025-12-12 13:43:25 +08:00
Bo-Yi Wu
93ff771e6d
ci(sec): improve type safety and server organization in HTTP middleware (#4437)
- Update linting configuration to exclude G115 gosec check instead of including specific checks
- Add the safeInt8 helper for safer type conversions and use it to prevent int8 overflow in middleware handler execution
- Group related constants and variables together for better organization in gin.go
- Refactor HTTP server instantiation to use a dedicated http.Server object for all Run methods
- Add the safeUint16 helper and use it to safely handle conversions in tree node functions to prevent uint16 overflow

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-11-15 23:03:32 +08:00
Name
2e22e50859
perf(tree): optimize path parsing using strings.Count (#4246)
Co-authored-by: 1911860538 <alxps1911@gmail.com>
2025-10-31 22:09:07 +08:00
Name
9b1e3533e2
refactor(tree): replace string(/) with "/" in node.insertChild (#4354)
Co-authored-by: 1911860538 <alxps1911@gmail.com>
2025-09-19 08:35:34 +08:00
Name
3d8e288c64
perf(all): use strings.Cut to replace strings.SplitN (#4239)
Co-authored-by: 1911860538 <alxps1911@gmail.com>
2025-05-20 22:58:34 +08:00
Xinyu Kuo
ea53388e6e
fix(tree): Keep panic infos consistent when wildcard type build faild (#4077) 2024-10-26 08:28:59 +08:00
wssccc
4621b7ac98
feat(router): add literal colon support (#1432) (#2857) 2024-06-01 13:44:57 +08:00
Endless Paradox
334160bab7
chore(tree): replace the self-defined 'min' to official one (#3975) 2024-05-24 14:55:25 +08:00
Prakhar Gurunani
9f598a31aa
fix(router): catch-all conflicting wildcard (#3812)
* fix: catch-all conflicting wildcard

* add: test cases

* chore: update GitHub Actions configuration (#3792)

- Change the cron schedule from `'0 17 * * 5'` to `"0 17 * * 5"` in the file `.github/workflows/codeql.yml`
- Change the value of `language` from `['go']` to `["go"]` in the file `.github/workflows/codeql.yml`
- Change the value of `go-version` from `'^1.18'` to `"^1.18"` in the file `.github/workflows/gin.yml`
- Add `1.21` to the list of `go` versions and change the value of `test-tags` in the file `.github/workflows/gin.yml`
- Change the value of `if` condition from `matrix.go-version == '1.20.x'` to `matrix.go-version == '1.21.x'` in the file `.github/workflows/gin.yml`
- Change the value of `on` from `'*'` to `"*"` in the file `.github/workflows/goreleaser.yml`
- Change the name of the job from `name: Checkout` to `name: Checkout` in the file `.github/workflows/goreleaser.yml`
- Change the name of the job from `name: Set up Go` to `name: Set up Go` in the file `.github/workflows/goreleaser.yml`
- Change the value of `go-version` from `1.20` to `"^1"` in

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* chore(deps): bump github/codeql-action from 2 to 3 (#3806)

Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2 to 3.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/v2...v3)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* fix(sec): upgrade golang.org/x/crypto to 0.17.0 (#3832)

* ci(lint): update tooling and workflows for consistency (#3834)

* chore: update tooling and workflows for consistency

- Update the version of a tool in the GitHub workflow from `v1.52.2` to `v1.55.2`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* chore: refactor linter configuration in CI

- Remove the `depguard` linter from the `.golangci.yml` configuration

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* ci: refine CI workflow and test configurations

- Disable caching in the GitHub Actions workflow for `gin.yml`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* refactor: refactor return logic in tree operations

- Modify multiple return statements in `tree.go` to return a specific value instead of nothing

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

---------

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* chore(deps): update dependencies to latest versions (#3835)

* chore: update dependencies to latest versions

- Update `sonic` library from `v1.9.1` to `v1.10.2`
- Update `validator` library from `v10.16.0` to `v10.17.0`
- Update `go-isatty` library from `v0.0.19` to `v0.0.20`
- Update `go/codec`, `x/net`, and `protobuf` libraries to newer versions
- Update `base64x` to a newer commit and add `iasm` library as an indirect dependency
- Update `mimetype`, `cpuid`, `go-urn`, `x/arch`, `x/crypto`, and `x/sys` libraries to newer versions

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* ci: refactor CI workflows and improve robustness

- Update GitHub Actions cache from v3 to v4 in the workflow configuration

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

---------

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* wip: fix tests

* wip: fix tests

---------

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: caption <101684156+chncaption@users.noreply.github.com>
2024-02-04 21:14:29 +08:00
Bo-Yi Wu
8ab47c694e
ci(lint): update tooling and workflows for consistency (#3834)
* chore: update tooling and workflows for consistency

- Update the version of a tool in the GitHub workflow from `v1.52.2` to `v1.55.2`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* chore: refactor linter configuration in CI

- Remove the `depguard` linter from the `.golangci.yml` configuration

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* ci: refine CI workflow and test configurations

- Disable caching in the GitHub Actions workflow for `gin.yml`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* refactor: refactor return logic in tree operations

- Modify multiple return statements in `tree.go` to return a specific value instead of nothing

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

---------

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-02-01 11:03:26 +08:00
Georgi Dimitrov
386d244068
fix(tree): correctly expand the capacity of params (#3502) 2023-12-07 08:38:55 +08:00
Kristian Svalland
8eb5f832ba
fix(router): tree bug where loop index is not decremented. (#3460)
fixes https://github.com/gin-gonic/gin/issues/3459
2023-01-07 08:57:54 +08:00
thinkerou
8b9c55e8b0
fix(route): redirectSlash bug (#3227)
fixes https://github.com/gin-gonic/gin/issues/2959
fixes https://github.com/gin-gonic/gin/issues/2282
fixes https://github.com/gin-gonic/gin/issues/2211
2022-11-06 17:02:40 +08:00
LanLanceYuan
815122a0f4
Fix a syntax error in a code comment (#3201) 2022-06-15 17:31:44 +08:00
Mike
1e24473f5f
Annotation fix (#3088)
* fix annotation

* fix annotation
2022-03-20 21:26:12 +08:00
MichaelDeSteven
41d38fb68c
fix typo (#3044) 2022-02-05 09:30:38 +08:00
jincheng9
7d189814cb
fix: wrong when wildcard follows named param (#2983) 2021-12-12 13:30:33 +08:00
Serica
a06d546f5c
prettify error message for catch-all conflict with existing path segment (#2934) 2021-11-28 09:26:17 +08:00
Ibraheem Ahmed
cbdd47a7e1
fix tsr with mixed static and wildcard paths (#2924) 2021-11-01 08:21:37 +08:00
市民233
1c2aa59b20
fix the misplacement of adding slashes (#2847) 2021-10-26 18:15:29 +08:00
Zhu Xi
3fe928994b
Update the code logic for latestNode in tree.go (#2897) 2021-10-23 11:58:57 +08:00
Alexander Melentyev
f3a6b69fd0
Delete unused static const (#2830) 2021-08-20 08:38:24 +08:00
qm012
0a55865c3f
fix #2786 (#2796)
* update match rule

* add comments
2021-07-26 10:07:54 +08:00
qm012
d4ca9a0fb1
fix #2762 (#2767) 2021-07-23 06:58:15 +08:00
raymonder jin
1d0f938f28
Fix insufficient slice check (#2755) 2021-06-25 13:22:01 +08:00
Ashwani
a8857ed70a
updated comments for Get function for params (#2756) 2021-06-23 11:36:24 +08:00
youzeliang
61a0cda75a
Update tree.go (#2659)
delete more "()"
2021-06-23 06:44:39 +08:00
Yue Yang
2921582d11
Fix conflict between param and exact path (#2706)
* Fix conflict between param and exact path

Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>

* Add test

Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>

* Fix prefix conflict in exact paths

Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>

* Use backtracking

Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>

* Fix panic

Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>
2021-05-19 10:05:36 +08:00
Ross Wolf
f3de8132c5
Add mixed param and non-param paths (port of httprouter#329) (#2663)
Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2021-04-06 10:49:08 +08:00
thinkerou
a573ec6a37
chore: update tree (#2371)
Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2021-01-03 21:34:11 +08:00
bestgopher
7bffae1d3d
Remove some functions that have the same effect as the bytes package (#2387) 2020-05-23 22:19:37 +08:00
Bo-Yi Wu
b4c8bf1bbe
chore(performance): improve countParams (#2378)
* update

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* chore: update

* chore: improve countParams performance

* update

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* chore: add comment
2020-05-17 18:11:22 +08:00
vinhha96
a6e8665e42
fix(tree): reassign fullpath when register new node which the same current node (#2366)
* fix(tree): assign fullpath to current node by fullpath of new node if current node the same new node

* test(router-test): reverse the order when register router when test func GetFullPath

* chg(tree-test): update test case with register new route in TestRouteContextHoldsFullPath

Co-authored-by: vinhha <vinhha@vng.com.vn>
Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-05-11 13:25:49 +08:00
Bo-Yi Wu
d17270dd90
Sync route tree to httprouter latest code (#2368)
* update tree

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* update

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* update

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* update countParams

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* fix testing

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* update

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* update

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* udpate

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* fix testing

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* refactor gin context

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* add fullPath

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* chore: refactor

* remove unused code

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* remove varsCount

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* refactor

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-05-10 13:22:25 +08:00
thinkerou
acac7b1210
tree: range over nodes values (#2229) 2020-02-09 10:46:22 +08:00
Bo-Yi Wu
0e4d8eaf07
tree: remove duplicate assignment (#2222)
copy from cfa3cb764b

Co-authored-by: thinkerou <thinkerou@gmail.com>
2020-01-28 18:35:47 +08:00
Bo-Yi Wu
64e6a7654f docs(path): improve comments (#2223)
* chore(path): improve comments

copy from 15782a78c6

* fix typo

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-01-28 11:38:45 +08:00
thinkerou
d6143d8d7c tree: remove one else statement (#2177) 2019-12-18 16:58:38 +08:00
thinkerou
168fa94516
tree: sync httprouter update (#2173) 2019-12-09 15:04:35 +08:00
thinkerou
6e16da8683
tree: sync httprouter update (#2172) 2019-12-08 19:34:05 +08:00
thinkerou
c6544855d7 tree: sync httprouter update (#2171) 2019-12-08 18:35:08 +08:00
thinkerou
7c21e04f62
fix maxParams bug (#2166) 2019-12-04 07:56:01 +08:00
thinkerou
3abc96e3cd
tree: sync part httprouter codes and reduce if/else (#2163) 2019-12-01 19:53:03 +08:00
ZYunH
b562fed3aa Make countParams more readable (#2052) 2019-09-11 18:10:39 +08:00
bbiao
f65018d7b1 Bugfix for the FullPath feature (#1919)
* worked with more complex situations
 * the original pr not work when and a short route with the same prefix
 to some already added routes
2019-06-28 23:54:52 +08:00
Roman Zaynetdinov
35e33d3638 Hold matched route full path in the Context (#1826)
* Return nodeValue from getValue method

* Hold route full path in the Context

* Add small example
2019-05-26 08:20:21 +08:00
Kirill Motkov
b1d607a899 Some code improvements (#1909)
* strings.ToLower comparison changed to strings.EqualFold.
* Rewrite switch statement with only one case as if.
2019-05-21 23:08:52 +08:00