forked from kataras/iris
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
37 lines (30 loc) · 762 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
31
32
33
34
35
36
37
package main
import "github.com/kataras/iris/v12"
func main() {
app := iris.New()
app.OnErrorCode(iris.StatusNotFound, notFound)
// [register some routes...]
app.Get("/home", handler)
app.Get("/news", handler)
app.Get("/news/politics", handler)
app.Get("/user/profile", handler)
app.Get("/user", handler)
app.Get("/newspaper", handler)
app.Get("/user/{id}", handler)
app.Listen(":8080")
}
func notFound(ctx iris.Context) {
suggestPaths := ctx.FindClosest(3)
if len(suggestPaths) == 0 {
ctx.WriteString("404 not found")
return
}
ctx.HTML("Did you mean?<ul>")
for _, s := range suggestPaths {
ctx.HTML(`<li><a href="%s">%s</a></li>`, s, s)
}
ctx.HTML("</ul>")
}
func handler(ctx iris.Context) {
ctx.Writef("Path: %s", ctx.Path())
}