Created
April 19, 2013 09:35
-
-
Save bernerdschaefer/5419244 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 CompletionCallback = func(duration time.Duration) { | |
microseconds := float64(duration / time.Microsecond) | |
requestLatency.Add(nil, microseconds) | |
} | |
func (registry registry) Handler() http.HandlerFunc { | |
return func(w http.ResponseWriter, r *http.Request) { | |
var instrumentable InstrumentableCall = func() { | |
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) | |
} | |
} | |
InstrumentCall(instrumentable, requestLatencyAccumulator) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment