Created
November 7, 2013 08:09
-
-
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
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 ( | |
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