add a more straightforward example for #1953

This commit is contained in:
Gerasimos (Makis) Maropoulos 2022-08-13 09:07:00 +03:00
parent 3715a66ef0
commit f91269130e
No known key found for this signature in database
GPG Key ID: 403EEB7885C79503
2 changed files with 31 additions and 0 deletions

View File

@ -55,6 +55,7 @@
* [Not Found - Intelligence](routing/intelligence/main.go)
* [Not Found - Suggest Closest Paths](routing/intelligence/manual/main.go)
* [Dynamic Path](routing/dynamic-path/main.go)
* [At-username](routing/dynamic-path/at-username/main.go)
* [Root Wildcard](routing/dynamic-path/root-wildcard/main.go)
* [Implement a Parameter Type](routing/macros/main.go)
* [Same Path Pattern but Func](routing/dynamic-path/same-pattern-different-func/main.go)

View File

@ -0,0 +1,30 @@
package main
import "github.com/kataras/iris/v12"
func main() {
app := iris.New()
app.Get("/", func(c iris.Context) {
c.Writef("Hello %s", "world")
})
// This is an Iris-only feature across all web frameworks
// in every programming language for years.
// Dynamic Route Path Parameters Functions.
// Set min length characters to 2.
// Prefix of the username is '@'
// Otherwise 404.
//
// You can also use the regexp(...) function for more advanced expressions.
app.Get("/{username:string min(2) prefix(@)}", func(ctx iris.Context) {
username := ctx.Params().Get("username")[1:]
ctx.Writef("Username is %s", username)
})
// http://localhost:8080 -> FOUND (Hello world)
// http://localhost:8080/other -> NOT FOUND
// http://localhost/@ -> NOT FOUND
// http://localhost:8080/@kataras -> FOUND (username is kataras)
app.Listen(":8080")
}