From 518607f2595945d3cddd5bdda6ee9d05f7d37a14 Mon Sep 17 00:00:00 2001 From: DarthSim Date: Thu, 6 Jun 2019 19:39:16 +0600 Subject: [PATCH] Require pprof build tag to enable net/pprof --- main.go | 9 --------- pprof.go | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 pprof.go diff --git a/main.go b/main.go index b3d5d3f0..ab3c398c 100644 --- a/main.go +++ b/main.go @@ -7,9 +7,6 @@ import ( "runtime/debug" "syscall" "time" - - "net/http" - _ "net/http/pprof" ) const version = "2.2.13" @@ -43,12 +40,6 @@ func main() { } }() - if len(os.Getenv("IMGPROXY_PPROF_BIND")) > 0 { - go func() { - http.ListenAndServe(os.Getenv("IMGPROXY_PPROF_BIND"), nil) - }() - } - s := startServer() stop := make(chan os.Signal, 1) diff --git a/pprof.go b/pprof.go new file mode 100644 index 00000000..92bba0d0 --- /dev/null +++ b/pprof.go @@ -0,0 +1,21 @@ +// +build pprof + +package main + +import ( + "net/http" + _ "net/http/pprof" + "os" +) + +func init() { + bind := os.Getenv("IMGPROXY_PPROF_BIND") + + if len(bind) == 0 { + bind = ":8088" + } + + go func() { + http.ListenAndServe(bind, nil) + }() +}