httprouter icon indicating copy to clipboard operation
httprouter copied to clipboard

panic: '/hello/:name' in new path '/hello/:name' conflicts with existing wildcar

Open Nemnon opened this issue 3 years ago • 1 comments

`package main

import ( "fmt" "github.com/julienschmidt/httprouter" "log" "net/http" )

func Hello(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { fmt.Fprintf(w, "hello, %s!\n", ps.ByName("name")) }

func main() { router := httprouter.New() router.ServeFiles("/*filepath", http.Dir("./templates")) router.GET("/hello/:name", Hello) log.Fatal(http.ListenAndServe(":8080", router)) }`

panic: '/hello/:name' in new path '/hello/:name' conflicts with existing wildcard '/*filepath' in existing prefix '/*filepath'

Nemnon avatar Mar 25 '22 03:03 Nemnon

julienschmidt/httprouter does not let you assign the same path to different Handles.

You defined a Wildcard in /*filepath, there could easily be a file under /hello/max that would collide with the path you tried to assign to the Hello Handle.

E.g. use /files/*filepath instead.

cerpmath123 avatar Dec 03 '24 18:12 cerpmath123