Skip to content

Commit

Permalink
feat(server): add debug pprof server
Browse files Browse the repository at this point in the history
  • Loading branch information
wufe committed Nov 24, 2023
1 parent e7a63d1 commit aefee0f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/server/pkg/models/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type RootConfiguration struct {
type GlobalConfiguration struct {
Host string
Port int
Debug bool `yaml:"debug,omitempty"`
TLSCertFile string `yaml:"tls_cert,omitempty"`
TLSKeyFile string `yaml:"tls_key,omitempty"`
SessionsFolder string `yaml:"sessions_folder"`
Expand Down
16 changes: 16 additions & 0 deletions packages/server/pkg/startup-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"github.com/wufe/polo/pkg/services"
"github.com/wufe/polo/pkg/storage"
"go.uber.org/dig"

_ "net/http/pprof"
)

type Startup struct {
Expand Down Expand Up @@ -119,6 +121,11 @@ func (s *Startup) Start(options *StartupOptions) {
if options.LoadSessionHelper {
s.static.LoadSessionHelper()
}

if s.configuration.Global.Debug {
s.startDebugServer()
}

if options.StartServer {
s.startServer()
}
Expand Down Expand Up @@ -213,3 +220,12 @@ func (s *Startup) startServer() {
}
}
}

func (s *Startup) startDebugServer() {
address := "0.0.0.0:7779"
s.log.Infof("Starting debug server on address %s", address)

go func() {
s.log.Infof("running debug server: %s", http.ListenAndServe(address, nil))
}()
}

0 comments on commit aefee0f

Please sign in to comment.