Skip to content

Instantly share code, notes, and snippets.

@smcquay
Created November 7, 2013 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smcquay/7350881 to your computer and use it in GitHub Desktop.
Save smcquay/7350881 to your computer and use it in GitHub Desktop.
This is an example of how to serve both a normal collection of routes and net/http/pprof on distinct addr:port in golang
package main
import (
jsonh "bitbucket.org/smcquay/json"
"encoding/json"
"fmt"
"log"
"net/http"
_ "net/http/pprof"
)
func hi(w http.ResponseWriter, r *http.Request) {
b, err := json.Marshal(r)
if err != nil {
log.Fatal(err)
}
fmt.Fprintf(w, string(b))
}
func main() {
go func() {
log.Println(http.ListenAndServe("localhost:8667", nil))
}()
sm := http.NewServeMux()
sm.Handle("/", jsonh.Handler(hi))
log.Println(http.ListenAndServe(":8666", sm))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment