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

router match mistake, when define named pattern and simple pattern simultaneously #1

Closed
cssivision opened this issue Feb 1, 2017 · 5 comments

Comments

@cssivision
Copy link

cssivision commented Feb 1, 2017

package main

import (
    "net/http"
    "github.com/teambition/trie-mux/mux"
)

func main() {
    router := mux.New()
    router.Get("/a/name", func(w http.ResponseWriter, _ *http.Request, _ mux.Params) {
        w.Write([]byte("hello world!\n"))
    })

    router.Get("/:name", func(w http.ResponseWriter, _ *http.Request, _ mux.Params) {
        w.Write([]byte("index\n"))
    })

    http.ListenAndServe(":8080", router)

}

i think path /a should match pattern /:name, but got response "/a" not implemented. when match path, simple pattern take precedence over named pattern. https://github.com/teambition/trie-mux/blob/master/trie.go#L132

@zensh
Copy link
Contributor

zensh commented Feb 1, 2017

It can't support implicit matching.

You should define router.Get("/a", handler)

@zensh
Copy link
Contributor

zensh commented Feb 1, 2017

There is Otherwise mathod on your demand

@cssivision
Copy link
Author

In my opinion, simple pattern take precedence over named pattern, /a conflict with /:a, if both of them exist, maybe there should be a panic.

There is other situation

package main

import (
    "net/http"
    "github.com/teambition/trie-mux/mux"
)

func main() {
    router := mux.New()
    router.Get("/a/b", func(w http.ResponseWriter, _ *http.Request, _ mux.Params) {
        w.Write([]byte("hello world!\n"))
    })

    router.Get("/:name/b", func(w http.ResponseWriter, _ *http.Request, _ mux.Params) {
        w.Write([]byte("index\n"))
    })

    http.ListenAndServe(":8080", router)
}

/a/b is conflict with /:name/b, path /b/b match /:name/b, but it's difficult to find the conflict between them, i can't solve this, so i post a issue.

@zensh
Copy link
Contributor

zensh commented Feb 3, 2017

Currently it is enough for practice usage with high performance. Don't make logic intricacy.

@cssivision
Copy link
Author

Yes, beyond is as wrong as falling short.

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