Skip to content

add exact router pre-router#262

Open
realityone wants to merge 4 commits into
mainfrom
exact-router-pr-261
Open

add exact router pre-router#262
realityone wants to merge 4 commits into
mainfrom
exact-router-pr-261

Conversation

@realityone
Copy link
Copy Markdown
Contributor

Add an optional exact pre-router for mux that indexes exact method, host, and path routes before falling back to gorilla/mux.

This PR is based on #261 and keeps its mux fast-path work while preserving gorilla/mux registration-order behavior for hostless and methodless routes.

Note: exactRouter is currently experimental. Use it at your own risk.

Closes #261.

# go test ./router/mux -run '^$' -bench BenchmarkRouteMatch -benchmem
goos: darwin
goarch: arm64
pkg: github.com/go-kratos/gateway/router/mux
cpu: Apple M4
BenchmarkRouteMatch/gorilla_mux-10         	   15996	     74620 ns/op	     848 B/op	       7 allocs/op
BenchmarkRouteMatch/exact_router-10        	31432572	        39.04 ns/op	       0 B/op	       0 allocs/op
PASS
ok  	github.com/go-kratos/gateway/router/mux	4.138s

Add an optional exact pre-router for mux that indexes exact method, host, and path routes before falling back to gorilla/mux.

This PR is based on #261 and keeps its mux fast-path work while preserving gorilla/mux registration-order behavior for hostless and methodless routes.

Note: exactRouter is currently experimental. Use it at your own risk.

Closes #261.
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Apr 27, 2026
Comment thread router/mux/prerouter.go
"github.com/gorilla/mux"
)

type PreRouter interface {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot PreRouter 还有没有更好的设计思路

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants