简体   繁体   English

使用 httprouter golang 包时将命名参数传递给索引模板

[英]passing named parameters to index template while using httprouter golang package

I just learnt how to use the httprouter go package and read many documents about it but failed to use the :name style of passing paramenters toe templates when it comes to the index page template.我刚刚学会了如何使用httprouter go 包并阅读了许多关于它的文档,但在涉及索引页面模板时未能使用 :name 样式传递参数 toe 模板。

ex.前任。

My router code:我的路由器代码:

    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
}

Then i get this error:然后我得到这个错误:

panic: wildcard segment ':email' conflicts with existing children in path '/:email'恐慌:通配符段“:电子邮件”与路径“/:电子邮件”中的现有子项冲突

所以它应该与 /user/:email 一起工作,而不仅仅是 /:email。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM