go - 在使用 httprouter golang 包时将命名参数传递给索引模板
问题描述
我刚刚学习了如何使用httprouter go 包并阅读了许多有关它的文档,但是在涉及到索引页面模板时,未能使用传递参数 toe 模板的 :name 样式。
前任。
我的路由器代码:
func getRouter() *httprouter.Router {
// Load and parse templates (from binary or disk)
templateBox = rice.MustFindBox("templates")
templateBox.Walk("", newTemplate)
// mux handler
router := httprouter.New()
// Example route that encounters an error
router.GET("/broken/handler", broken)
// Index route
router.GET("/:email", index)
router.GET("/read/all", readingHandler)
router.POST("/submit/newcon", Handler1)
router.POST("/read/newcon", Handler2)
// Serve static assets via the "static" directory
fs := rice.MustFindBox("static").HTTPBox()
router.ServeFiles("/static/*filepath", fs)
return router
}
然后我得到这个错误:
恐慌:通配符段 ':email' 与路径 '/:email' 中的现有子级冲突
解决方案
所以它应该与 /user/:email 一起工作,而不仅仅是 /:email。
推荐阅读
- python - 在python中的列表框之间移动项目
- java - 适用于 Java 项目的 Azure DevOps Pipeline 与自托管代理
- go - 如何将 int 切片转换为字符串切片
- linq - 在 LINQ 中将时间跨度转换为字符串
- tfs - 在源代码管理资源管理器中看不到项目
- c - C:相同签名功能的链接错误
- php - 在网站中使用 CSS 类查找 style.css
- php - WooCommerce 自定义支付网关:只需根据总订单显示额外费用
- javascript - 词法或预处理器问题 - 未找到 event2/event-config.h 文件
- android - Android Studio 向上滑动按钮