add debug http endpoint for expvar and pprof api
This commit is contained in:
parent
d789cd77e0
commit
e9396f2d6f
@ -15,6 +15,9 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/sixt/gomodproxy/pkg/api"
|
"github.com/sixt/gomodproxy/pkg/api"
|
||||||
|
|
||||||
|
_ "expvar"
|
||||||
|
_ "net/http/pprof"
|
||||||
)
|
)
|
||||||
|
|
||||||
func prettyLog(v ...interface{}) {
|
func prettyLog(v ...interface{}) {
|
||||||
@ -53,6 +56,7 @@ func main() {
|
|||||||
|
|
||||||
addr := flag.String("addr", ":0", "http server address")
|
addr := flag.String("addr", ":0", "http server address")
|
||||||
verbose := flag.Bool("v", false, "verbose logging")
|
verbose := flag.Bool("v", false, "verbose logging")
|
||||||
|
debug := flag.Bool("debug", false, "enable debug HTTP API (pprof/expvar)")
|
||||||
json := flag.Bool("json", false, "json structured logging")
|
json := flag.Bool("json", false, "json structured logging")
|
||||||
dir := flag.String("dir", filepath.Join(os.Getenv("HOME"), ".gomodproxy"), "cache directory")
|
dir := flag.String("dir", filepath.Join(os.Getenv("HOME"), ".gomodproxy"), "cache directory")
|
||||||
memLimit := flag.Int64("mem", 256, "in-memory cache size in MB")
|
memLimit := flag.Int64("mem", 256, "in-memory cache size in MB")
|
||||||
@ -69,7 +73,7 @@ func main() {
|
|||||||
fmt.Println("Listening on", ln.Addr())
|
fmt.Println("Listening on", ln.Addr())
|
||||||
|
|
||||||
options := []api.Option{}
|
options := []api.Option{}
|
||||||
var logger func(...interface{})
|
logger := func(...interface{}) {}
|
||||||
if *verbose || *json {
|
if *verbose || *json {
|
||||||
if *json {
|
if *json {
|
||||||
logger = jsonLog
|
logger = jsonLog
|
||||||
@ -95,7 +99,17 @@ func main() {
|
|||||||
sigc := make(chan os.Signal, 1)
|
sigc := make(chan os.Signal, 1)
|
||||||
signal.Notify(sigc, os.Interrupt)
|
signal.Notify(sigc, os.Interrupt)
|
||||||
|
|
||||||
srv := &http.Server{Handler: api.New(options...)}
|
mux := http.NewServeMux()
|
||||||
|
mux.Handle("/", api.New(options...))
|
||||||
|
if *debug {
|
||||||
|
mux.Handle("/debug/vars", http.DefaultServeMux)
|
||||||
|
mux.Handle("/debug/pprof/heap", http.DefaultServeMux)
|
||||||
|
mux.Handle("/debug/pprof/profile", http.DefaultServeMux)
|
||||||
|
mux.Handle("/debug/pprof/block", http.DefaultServeMux)
|
||||||
|
mux.Handle("/debug/pprof/trace", http.DefaultServeMux)
|
||||||
|
}
|
||||||
|
|
||||||
|
srv := &http.Server{Handler: mux}
|
||||||
go func() {
|
go func() {
|
||||||
if err := srv.Serve(ln); err != nil {
|
if err := srv.Serve(ln); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user