Skip to content

Commit 4fe5f3e

Browse files
y-yagiappleboy
andauthored
Use Duration.Truncate for truncating precision (gin-gonic#2711)
`Duration.Truncate` was added in Go 1.9 and Gin required Go version 1.13+ now. So we can use `Duration.Truncate`. Co-authored-by: Bo-Yi Wu <[email protected]>
1 parent 5452a1d commit 4fe5f3e

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

logger.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ var defaultLogFormatter = func(param LogFormatterParams) string {
138138
}
139139

140140
if param.Latency > time.Minute {
141-
// Truncate in a golang < 1.8 safe way
142-
param.Latency = param.Latency - param.Latency%time.Second
141+
param.Latency = param.Latency.Truncate(time.Second)
143142
}
144143
return fmt.Sprintf("[GIN] %v |%s %3d %s| %13v | %15s |%s %-7s %s %#v\n%s",
145144
param.TimeStamp.Format("2006/01/02 - 15:04:05"),

0 commit comments

Comments
 (0)