Skip to content

Instantly share code, notes, and snippets.

@h4ck4life
Created December 31, 2023 03:08
Show Gist options
  • Save h4ck4life/53b679cf3464fb1f687553ac004d5ecb to your computer and use it in GitHub Desktop.
Save h4ck4life/53b679cf3464fb1f687553ac004d5ecb to your computer and use it in GitHub Desktop.
Run go pprof with API server
package main
import (
"fmt"
"log"
"net/http"
_ "net/http/pprof" // Import for pprof
)
func main() {
// Register a sample API endpoint
http.HandleFunc("/api", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Hello, this is the API endpoint!")
})
// Start the server on localhost:8080
log.Println("Server starting on http://localhost:8080")
log.Fatal(http.ListenAndServe("localhost:8080", nil))
// then run the following command in your terminal:
// go tool pprof http://localhost:8080/debug/pprof
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment