forked from whyrusleeping/dhtHell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
viz.go
32 lines (29 loc) · 706 Bytes
/
viz.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
package main
import (
"fmt"
"net/http"
"time"
"github.com/jbenet/go-ipfs/diagnostics"
)
// Runs the visualization server to view d3 graph of the network
func RunServer(s string) {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "index.html")
})
http.HandleFunc("/data", func(w http.ResponseWriter, r *http.Request) {
nd, ok := controllers[0].(*localNode)
if !ok {
fmt.Println("Invalid controller type!")
return
}
diag, err := nd.n.Diagnostics.GetDiagnostic(time.Second * 5)
if err != nil {
fmt.Println(err)
}
w.Write(diagnostics.GetGraphJson(diag))
})
err := http.ListenAndServe(s, nil)
if err != nil {
fmt.Println(err)
}
}