Add new placeholder for latency in milliseconds

This commit is contained in:
Aish Raj Dahal
2016-10-05 21:02:45 -07:00
parent 20a54d0e07
commit 733f622f7a
2 changed files with 29 additions and 0 deletions
+11
View File
@@ -286,11 +286,22 @@ func (r *replacer) getSubstitution(key string) string {
return r.emptyValue
}
return roundDuration(time.Since(r.responseRecorder.start)).String()
case "{latency_ms}":
if r.responseRecorder == nil {
return r.emptyValue
}
elapsedDuration := time.Since(r.responseRecorder.start)
return strconv.FormatInt(convertToMilliseconds(elapsedDuration), 10)
}
return r.emptyValue
}
//convertToMilliseconds returns the number of milliseconds in the given duration
func convertToMilliseconds(d time.Duration) int64 {
return d.Nanoseconds() / 1e6
}
// Set sets key to value in the r.customReplacements map.
func (r *replacer) Set(key, value string) {
r.customReplacements["{"+key+"}"] = value