diff --git a/.env.tools b/.env.tools index 61bd6ab..a7f0723 100644 --- a/.env.tools +++ b/.env.tools @@ -1 +1 @@ -export TOOLS_BUILDNUMBER=20240829.1 +export TOOLS_BUILDNUMBER=20241108.3 diff --git a/httpserver/pprofserver.go b/httpserver/pprofserver.go new file mode 100644 index 0000000..f4cb814 --- /dev/null +++ b/httpserver/pprofserver.go @@ -0,0 +1,22 @@ +package httpserver + +import ( + "net/http" + "net/http/pprof" + + "github.com/datatrails/go-datatrails-common/environment" +) + +func NewPPROF(log Logger, name string) *Server { + port, err := environment.GetRequired("PPROF_PORT") + if err != nil { + return nil + } + h := http.NewServeMux() + h.HandleFunc(prefix+"/debug/pprof/", prof.Index) + h.HandleFunc(prefix+"/debug/pprof/cmdline", prof.Cmdline) + h.HandleFunc(prefix+"/debug/pprof/profile", prof.Profile) + h.HandleFunc(prefix+"/debug/pprof/symbol", prof.Symbol) + h.HandleFunc(prefix+"/debug/pprof/trace", prof.Trace) + return New(log, name, port, h) +} diff --git a/startup/listener.go b/startup/listener.go index e701218..69f00a3 100644 --- a/startup/listener.go +++ b/startup/listener.go @@ -44,6 +44,17 @@ func WithListeners(listeners ...Listener) ListenersOption { } } +// WithOptionalListeners add multiple listeners. Nil listeners are ignored. +func WithOptionalListeners(listeners ...Listener) ListenersOption { + return func(l *Listeners) { + for _, listener := range listeners { + if listener != nil { + l.listeners = append(l.listeners, listener) + } + } + } +} + func NewListeners(log Logger, name string, opts ...ListenersOption) Listeners { l := Listeners{name: strings.ToLower(name)} for _, opt := range opts {