Created
December 31, 2023 03:08
-
-
Save h4ck4life/53b679cf3464fb1f687553ac004d5ecb to your computer and use it in GitHub Desktop.
Run go pprof with API server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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