main.go 656 B

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