nebula/http.go
Tim Vaillancourt af958676b8 Cleanup code
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
2023-07-07 02:00:30 +02:00

35 lines
824 B
Go

package nebula
import (
"fmt"
"net/http"
_ "net/http/pprof"
"github.com/sirupsen/logrus"
"github.com/slackhq/nebula/config"
)
// startHttp returns a function to start an http server with pprof support and optionally, a provided stats
// http handler.
func startHttp(l *logrus.Logger, c *config.C, listen string, statsHandler statsHandlerFunc) (func(), error) {
if listen == "" {
return nil, nil
}
var statsPath string
if statsHandler != nil {
statsPath = c.GetString("stats.path", "")
if statsPath == "" {
return nil, fmt.Errorf("stats.path should not be empty")
}
}
return func() {
l.Infof("Go pprof handler listening on %s at /debug/pprof", listen)
if statsHandler != nil {
http.Handle(statsPath, statsHandler(listen, statsPath))
}
l.Fatal(http.ListenAndServe(listen, nil))
}, nil
}