3.10 路由树-参数路径之校验
本节课工程结构如下:
(base) yanglei@yuanhong 15-validateParamRoute % tree ./
./
├── context.go
├── handleFunc.go
├── httpServer.go
├── httpServer_test.go
├── node.go
├── router.go
├── router_test.go
└── serverInterface.go
0 directories, 8 filesPART1. 参数路由与通配符路由共存问题
1.1 修改逻辑
上节课中说过,我们的设计中是不准备支持同样的参数路径和通配符匹配一起注册的(即/user/*和/user/:id).
所以从逻辑上来讲,只需要实现:注册参数路由时检测通配符路由是否存在;注册通配符路由时检测参数路由是否存在.若对方存在,则不允许注册即可.
node.go:
1.2 测试
router_test.go:
以上两个测试用例均可顺利通过.
Last updated