-
-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathmain.go
49 lines (39 loc) · 1.03 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
package main
import (
"fmt"
"net"
"net/http"
"os"
"github.com/gofiber/adaptor/v2"
"github.com/gofiber/fiber/v2"
"github.com/soheilhy/cmux"
"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, err := net.Listen("tcp", ":8093")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
m := cmux.New(l)
ws := http.NewServeMux()
// Fiber instance
app := fiber.New()
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Hello, World 👋!")
})
// Create statsviz server.
srv, err := statsviz.NewServer()
// Register Statsviz server on the fasthttp router.
app.Use("/debug/statsviz", adaptor.HTTPHandler(srv.Index()))
ws.HandleFunc("/debug/statsviz/ws", srv.Ws())
fmt.Println("Point your browser to http://localhost:8093/debug/statsviz/")
// Server start
go http.Serve(m.Match(cmux.HTTP1HeaderField("Upgrade", "websocket")), ws)
go app.Listener(m.Match(cmux.Any()))
m.Serve()
}