mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
add a more straightforward example for #1953
This commit is contained in:
parent
3715a66ef0
commit
f91269130e
|
@ -55,6 +55,7 @@
|
||||||
* [Not Found - Intelligence](routing/intelligence/main.go)
|
* [Not Found - Intelligence](routing/intelligence/main.go)
|
||||||
* [Not Found - Suggest Closest Paths](routing/intelligence/manual/main.go)
|
* [Not Found - Suggest Closest Paths](routing/intelligence/manual/main.go)
|
||||||
* [Dynamic Path](routing/dynamic-path/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)
|
* [Root Wildcard](routing/dynamic-path/root-wildcard/main.go)
|
||||||
* [Implement a Parameter Type](routing/macros/main.go)
|
* [Implement a Parameter Type](routing/macros/main.go)
|
||||||
* [Same Path Pattern but Func](routing/dynamic-path/same-pattern-different-func/main.go)
|
* [Same Path Pattern but Func](routing/dynamic-path/same-pattern-different-func/main.go)
|
||||||
|
|
30
_examples/routing/dynamic-path/at-username/main.go
Normal file
30
_examples/routing/dynamic-path/at-username/main.go
Normal 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")
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user