mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-07 08:06:37 +08:00
feat(core): RouterExtension 增加 HandleRaw 与 BasePath
Handle 经 cleanPath 归一化会剥掉尾部斜杠,插件无法同时声明 /resource 与 /resource/ 两条路由;部署关闭 gin 的 RedirectTrailingSlash 时,缺失的那条 直接 404。下游 OpenFlare 有 20 个历史列表接口依赖该行为。 - HandleRaw:与组前缀拼接但保留尾部斜杠,分配独立路由 ID; - BasePath:返回组的绝对前缀(根注册表为空串); - 作用域包装器为 HandleRaw 同样登记 OnDispose 反注册。 验证:go build 通过;go test ./... exit 0(48 包 ok); check_cordis_architecture.sh 0 violations;gofmt 干净。
This commit is contained in:
@@ -40,6 +40,20 @@ func (s *scopedRouterExtension) Handle(method, path string, handlers ...any) ext
|
||||
return rd
|
||||
}
|
||||
|
||||
// HandleRaw registers a trailing-slash-preserving route and tears it down with the scope.
|
||||
func (s *scopedRouterExtension) HandleRaw(method, path string, handlers ...any) extpoints.RouteDefinition {
|
||||
rd := s.underlying.HandleRaw(method, path, handlers...)
|
||||
routeID := rd.ID
|
||||
s.ctx.OnDispose(func() error {
|
||||
s.underlying.UnregisterByID(routeID)
|
||||
return nil
|
||||
})
|
||||
return rd
|
||||
}
|
||||
|
||||
// BasePath delegates to the wrapped group prefix.
|
||||
func (s *scopedRouterExtension) BasePath() string { return s.underlying.BasePath() }
|
||||
|
||||
func (s *scopedRouterExtension) GET(path string, handlers ...any) extpoints.RouteDefinition {
|
||||
return s.Handle("GET", path, handlers...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user