-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
main.go
40 lines (33 loc) · 907 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
38
39
40
package main
import (
"strings"
"time"
"github.com/kataras/iris/v12"
"github.com/arl/statsviz"
)
// $ go get github.com/arl/statsviz
func main() {
app := iris.New()
// Register a router wrapper for this one.
statsvizPath := "/debug/statsviz"
serveRoot := statsviz.IndexAtRoot(statsvizPath)
serveWS := statsviz.NewWsHandler(time.Second)
app.UseRouter(func(ctx iris.Context) {
// You can optimize this if branch, I leave it to you as an exercise.
if strings.HasPrefix(ctx.Path(), statsvizPath+"/ws") {
serveWS(ctx.ResponseWriter(), ctx.Request())
} else if strings.HasPrefix(ctx.Path(), statsvizPath) {
serveRoot(ctx.ResponseWriter(), ctx.Request())
} else {
ctx.Next()
}
})
//
// Register other routes.
app.Get("/", index)
// Navigate to: http://localhost:8080/debug/statsviz/
app.Listen(":8080")
}
func index(ctx iris.Context) {
ctx.WriteString("Hello, World!")
}