Search code examples
gotemplatesservernamed-parametershttprouter

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.

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'


Solution

  • so it should work with /user/:email instead of just /:email.