Last active
October 23, 2015 17:15
-
-
Save garukun/f60fd7daeafa29dc7755 to your computer and use it in GitHub Desktop.
Go Status Page Using expvar
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 status | |
import ( | |
"expvar" | |
"net/http" | |
"encoding/json" | |
) | |
// Status method dumps application variables and their values in JSON format. | |
func Status(writer http.ResponseWriter, request *http.Request) { | |
vars := make(map[string]string) | |
expvar.Do(func(kv expvar.KeyValue) { | |
vars[kv.Key] = kv.Value.String() | |
}) | |
// Need error handling and closing request body. | |
writer.Header().Set("Content-Type", "application/json; charset=UTF-8") | |
json.NewEncoder(writer).Encode(vars) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment