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

route.go Find函数匹配问题 #245

Open
zouyih opened this issue Sep 7, 2022 · 2 comments
Open

route.go Find函数匹配问题 #245

zouyih opened this issue Sep 7, 2022 · 2 comments

Comments

@zouyih
Copy link

zouyih commented Sep 7, 2022

func TestFindMatchAmbiguity(t *testing.T) {
	r := NewRoute()
	r.Add(&metapb.API{
		ID:         1,
		URLPattern: "/a/b/c",
		Method:     "*",
	})
	r.Add(&metapb.API{
		ID:         2,
		URLPattern: "/(string):x/b/e",
		Method:     "*",
	})

	params := make(map[string]string, 0)
	paramsFunc := func(name, value []byte) {
		params[string(name)] = string(value)
	}

	id, _ := r.Find([]byte("/a/b/e"), "GET", paramsFunc)
	fmt.Println(id, params)
}

输出:
0 map[]

预期是要匹配到api_id =2, 实际上匹配不了

@zouyih
Copy link
Author

zouyih commented Sep 7, 2022

func TestFindMatchAmbiguity(t *testing.T) {
	r := NewRoute()

	r.Add(&metapb.API{
		ID:         2,
		URLPattern: "/(string):x/b/e",
		Method:     "*",
	})

	params := make(map[string]string, 0)
	paramsFunc := func(name, value []byte) {
		params[string(name)] = string(value)
	}

	id, _ := r.Find([]byte("/a/b/e"), "GET", paramsFunc)
	fmt.Println(id, params)
}

输出:
2 map[x:a]

如果去掉api_id=1,才能匹配到结果

@zouyih
Copy link
Author

zouyih commented Sep 7, 2022

route的匹配算法只选了一个路径进行匹配,没有做错误回退处理,用深搜应该可以解决这个问题

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

1 participant