From 4fe5f3e4b4fe62c057ec22caee4908beeef5f59c Mon Sep 17 00:00:00 2001 From: y-yagi Date: Tue, 4 May 2021 23:38:14 +0900 Subject: [PATCH] Use `Duration.Truncate` for truncating precision (#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 --- logger.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/logger.go b/logger.go index d361b74d32..22138a8d30 100644 --- a/logger.go +++ b/logger.go @@ -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"),