-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
dynamic path regex #918
Comments
if you need |
Hello @Dexus, First of all you use wrong string function for regexp, it's Secondly, I think the expression of Thirdly, the However do it like @Zeno-Code says, using A full example for you import "regexp"
// ...
// func main...
latLonExpr := "^-?[0-9]{1,3}(?:\\.[0-9]{1,10})?$"
latLonRegex, err := regexp.Compile(latLonExpr)
if err != nil {
panic(err)
}
app.Macros().String.RegisterFunc("coordinate", func() func(paramName string) (ok bool) {
// MatchString is a type of func(string) bool, so we can return that as it's.
return latLonRegex.MatchString
})
app.Get("/coordinates/{lat:string coordinate() else 502}/{lon:string coordinate() else 502}", func(ctx iris.Context) {
ctx.Writef("Lat: %s | Lon: %s", ctx.Params().Get("lat"), ctx.Params().Get("lon"))
}) Request example: Happy coding! |
@kataras Damn it! Thanks for the tip. Sometimes I can't see the forest because of the trees. 🙄 |
…ataras#918 Former-commit-id: 457c1a94dc8d93e614e9da70e1ec2482fe0c5765
Hello,
when I try to use regex like:
I get can't get the route.
Also if i use something with
$
at end of the regex it said it's an illegal token.The text was updated successfully, but these errors were encountered: