【发布时间】:2020-09-19 16:58:28
【问题描述】:
我刚刚学会了如何使用 httprouter go 包并阅读了很多关于它的文档,但是 当涉及到索引时,未能使用传递参数脚趾模板的 :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' 中的现有子级冲突
【问题讨论】:
-
github.com/julienschmidt/httprouter#named-parameters "由于该路由器只有显式匹配,因此您不能为同一路径段注册静态路由和参数。例如您不能注册模式
/user/new和@ 987654324@同时请求同一个方法。”
标签: go templates server named-parameters httprouter