main.go 641 B

12345678910111213141516171819202122232425262728293031
  1. package main
  2. import (
  3. "log/slog"
  4. "net/http"
  5. "os"
  6. _ "net/http/pprof" // profiling
  7. _ "github.com/joho/godotenv/autoload" // automatically load .env files
  8. "github.com/charmbracelet/crush/cmd"
  9. "github.com/charmbracelet/crush/internal/log"
  10. )
  11. func main() {
  12. defer log.RecoverPanic("main", func() {
  13. slog.Error("Application terminated due to unhandled panic")
  14. })
  15. if os.Getenv("CRUSH_PROFILE") != "" {
  16. go func() {
  17. slog.Info("Serving pprof at localhost:6060")
  18. if httpErr := http.ListenAndServe("localhost:6060", nil); httpErr != nil {
  19. slog.Error("Failed to pprof listen", "error", httpErr)
  20. }
  21. }()
  22. }
  23. cmd.Execute()
  24. }