Last active
November 15, 2019 10:28
-
-
Save flowerinthenight/b6e639978dc2c21042ccea526700f214 to your computer and use it in GitHub Desktop.
Serving expvar when using gorilla/mux.
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 ( | |
"expvar" | |
"log" | |
"net/http" | |
"github.com/gorilla/mux" | |
) | |
var counter *expvar.Int | |
func init() { | |
counter = expvar.NewInt("counter") | |
} | |
func rootHandler(w http.ResponseWriter, r *http.Request) { | |
w.Write([]byte("Hello world!\n")) | |
counter.Add(1) | |
} | |
func main() { | |
r := mux.NewRouter() | |
r.HandleFunc("/", rootHandler) | |
r.Handle("/debug/vars", http.DefaultServeMux) | |
log.Fatal(http.ListenAndServe(":8000", r)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you use
Mux.Handle("/debug/{*}", http.DefaultServeMux)
then as well as the/debug/vars
routes the traces/debug/requests
/debug/events
Routes are also served.