debug.go 710 B

123456789101112131415161718192021222324252627282930313233
  1. //go:build debug
  2. package controller
  3. import (
  4. "context"
  5. "net/http"
  6. _ "net/http/pprof"
  7. "os"
  8. "os/signal"
  9. "github.com/gravitl/netmaker/logger"
  10. )
  11. func init() {
  12. srv := &http.Server{Addr: "0.0.0.0:6060", Handler: nil}
  13. go func() {
  14. logger.Log(0, "Debug mode active")
  15. err := srv.ListenAndServe()
  16. if err != nil {
  17. logger.Log(0, err.Error())
  18. }
  19. c := make(chan os.Signal)
  20. // Relay os.Interrupt to our channel (os.Interrupt = CTRL+C)
  21. // Ignore other incoming signals
  22. signal.Notify(c, os.Interrupt)
  23. // Block main routine until a signal is received
  24. // As long as user doesn't press CTRL+C a message is not passed and our main routine keeps running
  25. <-c
  26. srv.Shutdown(context.TODO())
  27. }()
  28. }