How to Use net/http/pprof for Live Profiling

Import net/http/pprof to expose profiling endpoints at /debug/pprof/ for live performance analysis.

Import the net/http/pprof package to automatically register profiling handlers at standard paths like /debug/pprof/. Start your HTTP server, then visit those endpoints in a browser or use go tool pprof to analyze CPU and memory usage.

package main

import (
	_ "net/http/pprof"
	"log"
	"net/http"
)

func main() {
	log.Println("Profiling available at http://localhost:8080/debug/pprof/")
	log.Fatal(http.ListenAndServe(":8080", nil))
}