使用httprouter golang包时将命名参数传递给索引模板
我刚刚学会了如何使用httprouter,并阅读了很多关于它的文档,但是 在索引中使用传递参数模板的:name样式失败 页面模板 前 我的路由器代码:使用httprouter golang包时将命名参数传递给索引模板,go,templates,server,named-parameters,httprouter,Go,Templates,Server,Named Parameters,Httprouter,我刚刚学会了如何使用httprouter,并阅读了很多关于它的文档,但是 在索引中使用传递参数模板的:name样式失败 页面模板 前 我的路由器代码: func getRouter() *httprouter.Router { // Load and parse templates (from binary or disk) templateBox = rice.MustFindBox("templates") templateBox.Walk
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
}
然后我得到这个错误:
panic:wildcard segment':email'与路径'/:email'中的现有子项冲突,因此它应该与/user/:email一起使用,而不仅仅是/:email。“由于此路由器只有显式匹配,您不能为同一路径段注册静态路由和参数。例如,您不能同时为相同的请求方法注册模式
/user/new
和/user/:user
。“非常感谢@Riley Worstell,我终于求助于通过URL查询参数接收电子邮件,效果很好。