知识卡片
路由匹配先于路径分割
直接从固定位置切路径,遇到更短的/league会越界。先由ServeMux把/league与/players/分派给不同处理器,再在匹配范围内提取参数,才能把不同端点隔离。原书称标准路由没有路径变量属于旧版背景;Go1.22起已支持方法及通配路径模式,应按项目版本选择。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- JSON,路由和嵌入 · 查看原书依据
0_on_/league panic: runtime error: slice bounds out of range [recovered] panic: runtime error: slice bounds out of range goroutine 6 [running]: testin
参考来源
- 位置:《通过测试学习 Go 编程》JSON,路由和嵌入,spine024(book-sources;extracted/通过测试学习 Go 编程/_epub-src/OEBPS/Text/23.html)。
- 结论依据:原文新增/league触发固定切片panic,随后引入ServeMux;新版本差异核验官方文档。
- 原始内容:0_on_/league panic: runtime error: slice bounds out of range [recovered] panic: runtime error: slice bounds out of range goroutine 6 [running]: testin
- 校正核验(2026-11-06):[一手资料](https://pkg.go.dev/net/http#ServeMux);本轮未运行示例。