Created
April 19, 2013 09:36
-
-
Save bernerdschaefer/5419250 to your computer and use it in GitHub Desktop.
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
// 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