mirror of
https://github.com/caddyserver/caddy.git
synced 2026-05-21 06:16:31 -04:00
Add new placeholder for latency in milliseconds
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user