-
-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathmain.go
36 lines (28 loc) · 823 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
package main
import (
"fmt"
"log"
"net/http"
"github.com/arl/statsviz"
"github.com/go-chi/chi"
example "github.com/arl/statsviz/_example"
)
func main() {
// Force the GC to work to make the plots "move".
go example.Work()
// Create statsviz server.
srv, _ := statsviz.NewServer()
// Create a chi router and register statsviz http handlers.
r := chi.NewRouter()
r.Get("/debug/statsviz/ws", srv.Ws())
r.Get("/debug/statsviz", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/debug/statsviz/", 301)
})
r.Handle("/debug/statsviz/*", srv.Index())
mux := http.NewServeMux()
mux.Handle("/", r)
fmt.Println("Point your browser to http://localhost:8081/debug/statsviz/")
if err := http.ListenAndServe(":8081", mux); err != nil {
log.Fatalf("failed to start server: %s", err)
}
}