Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic error #36

Closed
dryaf opened this issue Oct 12, 2014 · 1 comment
Closed

panic error #36

dryaf opened this issue Oct 12, 2014 · 1 comment

Comments

@dryaf
Copy link

dryaf commented Oct 12, 2014

Hi, I m serving a single page application from /

http.Handle("/", http.FileServer(http.Dir("./web_root")))
http.HandleFunc("/order_create", handlerOrderCreate)
http.HandleFunc("/order_show", handlerOrderShow)

--> works fine

router.ServeFiles("/*filepath", http.Dir("./web_root"))
router.GET( "/orders/:id", handlerOrderShow)
router.POST("/orders", handlerOrderCreate)

--> panic: conflict with wildcard route

goroutine 16 [running]:
runtime.panic(0x293240, 0xc208000980)
/usr/local/go/src/pkg/runtime/panic.c:279 +0xf5
github.com/julienschmidt/httprouter.(*node).addRoute(0xc2080042a0, 0x392f70, 0xb, 0x433330)
/Users/sallas/go/src/github.com/julienschmidt/httprouter/tree.go:141 +0x594

What could I do to make it work in /?

@julienschmidt
Copy link
Owner

By design of the router, one can not register multiple handlers for the same path segment. By /*filepath you tell the router to handle ANY request with http.Dir("./web_root"). Therefore you can not also register /orders/:id and /orders.
You can find a hack some people use in #33, but I would simply recommend to use a distinct sub-path for serving files like /static/*filepath or /files/*filepath.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants