Skip to content

Commit

Permalink
Use Duration.Truncate for truncating precision (#2711)
Browse files Browse the repository at this point in the history
`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 <appleboy.tw@gmail.com>
  • Loading branch information
y-yagi and appleboy committed May 4, 2021
1 parent 5452a1d commit 4fe5f3e
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions logger.go
Expand Up @@ -138,8 +138,7 @@ var defaultLogFormatter = func(param LogFormatterParams) string {
}

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

0 comments on commit 4fe5f3e

Please sign in to comment.