For personal reference:
This file contains hidden or 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)) | |
} |
Access root
http://localhost:8000
Access expvar information
http://localhost:8000/debug/vars