varz.go 494 B

12345678910111213141516171819202122232425
  1. package api
  2. import (
  3. "expvar"
  4. "fmt"
  5. "net/http"
  6. "github.com/ncarlier/webhookd/pkg/config"
  7. )
  8. func varz(conf *config.Config) http.Handler {
  9. return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  10. w.Header().Set("Content-Type", "application/json")
  11. fmt.Fprintf(w, "{\n")
  12. first := true
  13. expvar.Do(func(kv expvar.KeyValue) {
  14. if !first {
  15. fmt.Fprintf(w, ",\n")
  16. }
  17. first = false
  18. fmt.Fprintf(w, "%q: %s", kv.Key, kv.Value)
  19. })
  20. fmt.Fprintf(w, "\n}\n")
  21. })
  22. }