-
-
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
[QUESTION] dynamic routing does not take effect #2024
Comments
Hello @PalaChen, try to put the |
i try it but get is string not uint, /category/eee/555.html get 555.html but i want to get 555 |
Hello @PalaChen here is a working example: package main
import (
"github.com/kataras/iris/v12"
)
func main() {
app := iris.New()
app.Get("/{uid:string regexp(^[0-9]{1,20}.html$)}", iris.TrimParamFilePart, handler)
app.Listen(":8080")
}
func handler(ctx iris.Context) {
//
// The above line is useless now that we've registered the TrimFilePart middleware:
// uid := ctx.Params().GetTrimFileUint64("uid")
// TrimParamFilePart can be registered as a middleware, like the rest, to a group of routes too (Party).
uid := ctx.Params().GetUint64Default("uid", 0)
ctx.Writef("Param value: %d\n", uid)
} The func TrimParamFilePart(ctx iris.Context) {
params := ctx.Params()
for i, param := range params.Store {
if value, ok := param.ValueRaw.(string); ok {
if idx := strings.LastIndexByte(value, '.'); idx > 1 /* at least .h */ {
value = value[0:idx]
param.ValueRaw = value
}
}
params.Store[i] = param
}
ctx.Next()
} I've added an example of your case and an error message to protect others from doing the same. |
thanks |
You're welcome @PalaChen ! |
Describe the bug
regularly extract integers in URLs
To Reproduce
Steps to reproduce the behavior:
view
Expected behavior
url :
i want to
how to solve?
Desktop (please complete the following information):
mac
iris.Version
v12
Please make sure the bug is reproducible over the
master
branch:The text was updated successfully, but these errors were encountered: