-
-
Notifications
You must be signed in to change notification settings - Fork 178
/
main.go
30 lines (25 loc) · 892 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package main
import "github.com/kataras/iris/v12"
func main() {
app := iris.New()
app.Get("/", func(ctx iris.Context) {
ctx.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:8080/@ -> NOT FOUND
// http://localhost:8080/@kataras -> FOUND (username is kataras)
app.Listen(":8080")
}