-
-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathmain.go
44 lines (35 loc) · 1.05 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
package main
import (
"fmt"
"net"
"net/http"
"github.com/fasthttp/router"
"github.com/soheilhy/cmux"
"github.com/valyala/fasthttp"
"github.com/valyala/fasthttp/fasthttpadaptor"
"github.com/arl/statsviz"
example "github.com/arl/statsviz/_example"
)
func main() {
// Force the GC to work to make the plots "move".
go example.Work()
// Create the main listener and mux
l, _ := net.Listen("tcp", ":8083")
m := cmux.New(l)
ws := http.NewServeMux()
// fasthttp routers
r := router.New()
r.GET("/", func(ctx *fasthttp.RequestCtx) {
fmt.Fprintf(ctx, "Hello, world!")
})
// Create statsviz server.
srv, _ := statsviz.NewServer()
// Register Statsviz server on the fasthttp router.
r.GET("/debug/statsviz/{filepath:*}", fasthttpadaptor.NewFastHTTPHandler(srv.Index()))
ws.HandleFunc("/debug/statsviz/ws", srv.Ws())
// Server start
go http.Serve(m.Match(cmux.HTTP1HeaderField("Upgrade", "websocket")), ws)
go fasthttp.Serve(m.Match(cmux.Any()), r.Handler)
fmt.Println("Point your browser to http://localhost:8083/debug/statsviz/")
m.Serve()
}