1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-21 11:57:02 +00:00

make macros even faster and smart catch common :string and do not execute anything at all if not really needed, more clean code as well

Former-commit-id: 589c23d1f92cf36b7677dfe78b60d51252c979fb
This commit is contained in:
Gerasimos (Makis) Maropoulos
2018-09-28 05:34:35 +03:00
parent 972dff8729
commit bf880033cd
4 changed files with 87 additions and 35 deletions

View File

@@ -65,6 +65,24 @@ func main() {
return fmt.Sprintf("Value of the parameters are: %s:%d\n", myparam1, myparam2)
}))
app.Get("/test_string/{myparam1}/{myparam2 prefix(a)}", func(ctx context.Context) {
var (
myparam1 = ctx.Params().Get("myparam1")
myparam2 = ctx.Params().Get("myparam2")
)
ctx.Writef("myparam1: %s | myparam2: %s", myparam1, myparam2)
})
app.Get("/test_string2/{myparam1}/{myparam2}", func(ctx context.Context) {
var (
myparam1 = ctx.Params().Get("myparam1")
myparam2 = ctx.Params().Get("myparam2")
)
ctx.Writef("myparam1: %s | myparam2: %s", myparam1, myparam2)
})
app.Get("test_uint64/{myparam1:string}/{myparam2:uint64}", func(ctx context.Context) {
// works: ctx.Writef("Value of the parameter is: %s\n", ctx.Params().Get("myparam"))
// but better and faster because the macro converts the string to uint64 automatically: