main.go 715 B

123456789101112131415161718192021222324252627282930313233
  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/internal/cmd"
  9. "github.com/charmbracelet/crush/internal/event"
  10. "github.com/charmbracelet/crush/internal/log"
  11. )
  12. func main() {
  13. defer log.RecoverPanic("main", func() {
  14. event.Flush()
  15. slog.Error("Application terminated due to unhandled panic")
  16. })
  17. if os.Getenv("CRUSH_PROFILE") != "" {
  18. go func() {
  19. slog.Info("Serving pprof at localhost:6060")
  20. if httpErr := http.ListenAndServe("localhost:6060", nil); httpErr != nil {
  21. slog.Error("Failed to pprof listen", "error", httpErr)
  22. }
  23. }()
  24. }
  25. cmd.Execute()
  26. }