1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-09-10 03:42:21 +08:00

Serve expvars and pprof on the API port

This commit is contained in:
Tommi Virtanen
2015-04-28 16:36:48 -07:00
parent b1183099a2
commit df70fe4ac7

View File

@ -1,7 +1,10 @@
package main
import (
_ "expvar"
"fmt"
"net/http"
_ "net/http/pprof"
"os"
"strings"
@ -76,6 +79,17 @@ the port as you would other services or database (firewall, authenticated proxy,
Run: daemonFunc,
}
// defaultMux tells mux to serve path using the default muxer. This is
// mostly useful to hook up things that register in the default muxer,
// and don't provide a convenient http.Handler entry point, such as
// expvar and http/pprof.
func defaultMux(path string) func(node *core.IpfsNode, mux *http.ServeMux) (*http.ServeMux, error) {
return func(node *core.IpfsNode, mux *http.ServeMux) (*http.ServeMux, error) {
mux.Handle(path, http.DefaultServeMux)
return mux, nil
}
}
func daemonFunc(req cmds.Request, res cmds.Response) {
// let the user know we're going.
fmt.Printf("Initializing daemon...\n")
@ -281,6 +295,8 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
corehttp.WebUIOption,
gateway.ServeOption(),
corehttp.VersionOption(),
defaultMux("/debug/vars"),
defaultMux("/debug/pprof/"),
}
if rootRedirect != nil {