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

Empty catch-all routes don't cache empty values #62

Closed
azavorotnii opened this issue Sep 14, 2018 · 1 comment
Closed

Empty catch-all routes don't cache empty values #62

azavorotnii opened this issue Sep 14, 2018 · 1 comment

Comments

@azavorotnii
Copy link

I am trying to use *path catch-all syntax to match both http://localhost:8080/example/some/path and http://localhost:8080/example/. I expect that catch-all syntax will handle latter with empty "path" param, but it doesn't. I got 404.

package main

import (
	"github.com/dimfeld/httptreemux"
	"net/http"
)

func main() {
	router := httptreemux.NewContextMux()
	h := func(w http.ResponseWriter, r *http.Request) {
		params := httptreemux.ContextParams(r.Context())
		w.Write([]byte(params["path"]))
	}
	router.GET("/example/*path", h)
	http.ListenAndServe(":8080", router)
}

I can workaround it with adding one more handler:

	router.GET("/example/*path", h)
	router.GET("/example/", h)

But I didn't have to do it with https://github.com/julienschmidt/httprouter

If this is not an issue by design, I would at least mention this in documentation :)

@dimfeld
Copy link
Owner

dimfeld commented Sep 14, 2018

Yes, this is intentional. I'll add something to the docs soon mentioning it. Thanks!

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