Skip to content

Instantly share code, notes, and snippets.

@mmcloughlin
Last active September 23, 2017 00:58
Show Gist options
  • Select an option

  • Save mmcloughlin/35fe28c93d72f75b360dc6527d169831 to your computer and use it in GitHub Desktop.

Select an option

Save mmcloughlin/35fe28c93d72f75b360dc6527d169831 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"log"
"net/http"
_ "net/http/pprof"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello World!")
})
log.Fatal(http.ListenAndServe(":8080", nil))
}
package main
import (
"fmt"
"log"
"net/http"
_ "net/http/pprof"
)
func main() {
// Pprof server.
go func() {
log.Fatal(http.ListenAndServe("localhost:8081", nil))
}()
// Application server.
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello World!")
})
log.Fatal(http.ListenAndServe(":8080", mux))
}
package main
import (
"fmt"
"log"
"net/http"
_ "net/http/pprof"
)
func main() {
// Save pprof handlers first.
pprofMux := http.DefaultServeMux
http.DefaultServeMux = http.NewServeMux()
// Pprof server.
go func() {
log.Fatal(http.ListenAndServe("localhost:8081", pprofMux))
}()
// Application server.
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello World!")
})
log.Fatal(http.ListenAndServe(":8080", nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment