forked from kataras/iris
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
70 lines (56 loc) · 1.94 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"github.com/kataras/iris"
)
func main() {
app := iris.New()
// this works as expected now,
// will handle all GET requests
// except:
// / -> because of app.Get("/", ...)
// /other/anything/here -> because of app.Get("/other/{paramother:path}", ...)
// /other2/anything/here -> because of app.Get("/other2/{paramothersecond:path}", ...)
// /other2/static2 -> because of app.Get("/other2/static", ...)
//
// It isn't conflicts with the rest of the routes, without routing performance cost!
//
// i.e /something/here/that/cannot/be/found/by/other/registered/routes/order/not/matters
app.Get("/{p:path}", h)
// app.Get("/static/{p:path}", staticWildcardH)
// this will handle only GET /
app.Get("/", staticPath)
// this will handle all GET requests starting with "/other/"
//
// i.e /other/more/than/one/path/parts
app.Get("/other/{paramother:path}", other)
// this will handle all GET requests starting with "/other2/"
// except /other2/static (because of the next static route)
//
// i.e /other2/more/than/one/path/parts
app.Get("/other2/{paramothersecond:path}", other2)
// this will handle only GET "/other2/static"
app.Get("/other2/static2", staticPathOther2)
app.Run(iris.Addr(":8080"), iris.WithoutServerError(iris.ErrServerClosed))
}
func h(ctx iris.Context) {
param := ctx.Params().Get("p")
ctx.WriteString(param)
}
func staticWildcardH(ctx iris.Context) {
param := ctx.Params().Get("p")
ctx.WriteString("from staticWildcardH: param=" + param)
}
func other(ctx iris.Context) {
param := ctx.Params().Get("paramother")
ctx.Writef("from other: %s", param)
}
func other2(ctx iris.Context) {
param := ctx.Params().Get("paramothersecond")
ctx.Writef("from other2: %s", param)
}
func staticPath(ctx iris.Context) {
ctx.Writef("from the static path(/): %s", ctx.Path())
}
func staticPathOther2(ctx iris.Context) {
ctx.Writef("from the static path(/other2/static2): %s", ctx.Path())
}