package main

import (
	"fmt"
	"net/http"
	_ "net/http/pprof" // Register pprof handlers
)

// section: server
func main() {
	// Start pprof server on separate port
	go func() {
		fmt.Println("pprof server: http://localhost:6060/debug/pprof/")
		http.ListenAndServe(":6060", nil)
	}()

	// Your application code here
	fmt.Println("Application running...")
	fmt.Println("Check for leaks: curl http://localhost:6060/debug/pprof/goroutineleak?debug=2")

	select {} // Block forever
}

// section: server

/*
// section: usage
To check for goroutine leaks in production:

# Build with goroutineleak support
$ GOEXPERIMENT=goroutineleakprofile go build

# Query the endpoint (debug levels: 0=protobuf, 1=compact, 2=full traces)
$ curl http://localhost:6060/debug/pprof/goroutineleak?debug=2

# Example output showing a leak:
goroutine 42 [chan send (leaked)]:
main.processWorkItems.func1()
    /app/worker.go:25 +0x45
created by main.processWorkItems
    /app/worker.go:20 +0x123

The "(leaked)" annotation indicates the goroutine is blocked on an
unreachable synchronization primitive and will never complete.
// section: usage
*/
