iris
iris copied to clipboard
[BUG] Routing couldn't distinguish slashes even though I have the right regexp
Describe the bug
I want to combine multiple routes with slashes into a single parameter, like /*/suffix
or /**/suffix
, and /a/suffix
, ab/cd/suffix
, a1/b2/c3/d-4/suffix
can match the rule, but it seems iris couldn't do this now (path
is not suitable because I have other suffix like /a/b/c/suffix/another-suffix/and-more-suffix
).
So, I wrote a regexp, and registered a custom macros, like this:
regex := regexp.MustCompile("^[a-z0-9/-]+$")
app.Macros().Get("string").RegisterFunc("name", regex.MatchString)
assert.True(t, regex.MatchString("abc/def/ghi"))
I thought this would work, and /ab/cd/ef/anything-else
could match /{name:string name()}/anything-alse
, but actually, it didn't!
It seems that al slashes couldn't combine to a single param, maybe except path
.
Could you please tell me how to implement my requirement above? I am puzzled now..
To Reproduce Steps to reproduce the behavior:
- register a custom macros:
regex := regexp.MustCompile("^[a-z0-9/-]+$")
app.Macros().Get("string").RegisterFunc("name", regex.MatchString)
- register a routing:
app.Get("/{name:string name()}/balabala", helloWorldHandler)
- try to get
curl localhost:8080/a/b/c/balabala
Not Found
Expected behavior
curl localhost:8080/a/b/c/balabala
hello, world!
and we could get the param name
:
ctx.Params().Get("name") // "a/b/c"
Desktop (please complete the following information):
- OS: Ubuntu 18.04.LTS
- Go: go version go1.15 linux/amd64
iris.Version
- v12.1.9-0.20200814001959-6fee09f11ed1
Hello ? @kataras