Skip to content

Instantly share code, notes, and snippets.

@bernerdschaefer
Created April 19, 2013 09:36
Show Gist options
  • Save bernerdschaefer/5419250 to your computer and use it in GitHub Desktop.
Save bernerdschaefer/5419250 to your computer and use it in GitHub Desktop.
// This callback accumulates the microsecond duration of the reporting
// framework's overhead such that it can be reported.
var requestLatencyAccumulator = func(began time.Time) {
microseconds := float64(time.Since(began) / time.Microsecond)
requestLatency.Add(nil, microseconds)
}
func (registry registry) Handler() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
defer requestLatencyAccumulator(time.Now())
requestCount.Increment(nil)
url := r.URL
if strings.HasSuffix(url.Path, jsonSuffix) {
header := w.Header()
header.Set(ProtocolVersionHeader, APIVersion)
header.Set(contentTypeHeader, jsonContentType)
writer := decorateWriter(r, w)
if closer, ok := writer.(io.Closer); ok {
defer closer.Close()
}
registry.dumpToWriter(writer)
} else {
w.WriteHeader(http.StatusNotFound)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment