gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 22:20:13 26 4
gpt4 key购买 nike

我刚刚学会了如何使用 http路由器去打包并阅读许多关于它的文件,但是
当涉及到索引时,未能使用传递参数脚趾模板的 :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
}
然后我得到这个错误:

panic :通配符段 ':email' 与路径 '/:email' 中的现有子级冲突

最佳答案

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

关于go - 在使用 httprouter golang 包时将命名参数传递给索引模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63971294/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com