Browse Source

Fix(restapi): debug missing mountpoints

pull/133/head
xjasonlyu 3 years ago
parent
commit
e4801c3989
  1. 4
      restapi/connections.go
  2. 4
      restapi/netstats.go
  3. 22
      restapi/server.go

4
restapi/connections.go

@ -16,6 +16,10 @@ import (
const defaultInterval = 1000
func init() {
registerMountPoint("/connections", connectionRouter())
}
func connectionRouter() http.Handler {
r := chi.NewRouter()
r.Get("/", getConnections)

4
restapi/netstats.go

@ -18,6 +18,10 @@ func SetStatsFunc(s func() tcpip.Stats) {
_statsFunc = s
}
func init() {
registerMountPoint("/netstats", http.HandlerFunc(getNetStats))
}
func getNetStats(w http.ResponseWriter, r *http.Request) {
if _statsFunc == nil {
render.Status(r, http.StatusInternalServerError)

22
restapi/server.go

@ -20,10 +20,18 @@ import (
"github.com/gorilla/websocket"
)
var _upgrader = websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool {
return true
},
var (
_upgrader = websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool {
return true
},
}
_mountPoints = make(map[string]http.Handler)
)
func registerMountPoint(pattern string, handler http.Handler) {
_mountPoints[pattern] = handler
}
func Start(addr, token string) error {
@ -43,8 +51,10 @@ func Start(addr, token string) error {
r.Get("/logs", getLogs)
r.Get("/traffic", traffic)
r.Get("/version", version)
r.Get("/netstats", getNetStats)
r.Mount("/connections", connectionRouter())
// attach HTTP handlers
for pattern, handler := range _mountPoints {
r.Mount(pattern, handler)
}
})
listener, err := net.Listen("tcp", addr)

Loading…
Cancel
Save