From c7f911cae298b77a506dd4b2c2ea5670c7c28af0 Mon Sep 17 00:00:00 2001 From: John Date: Mon, 16 Mar 2020 23:03:35 +0800 Subject: [PATCH] change function time.Duration.Milliseconds to time.Duration.Nanoseconds for compatibility of Golang version < 1.13 --- container/gpool/gpool.go | 4 +++- os/glog/glog_logger_rotate.go | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/container/gpool/gpool.go b/container/gpool/gpool.go index 93df5b3ba..efb84cf8e 100644 --- a/container/gpool/gpool.go +++ b/container/gpool/gpool.go @@ -82,7 +82,9 @@ func (p *Pool) Put(value interface{}) error { if p.TTL == 0 { item.expire = 0 } else { - item.expire = gtime.TimestampMilli() + p.TTL.Milliseconds() + // As for Golang version <= 1.13, there's no method Milliseconds for time.Duration. + // So we need calculate the milliseconds using its nanoseconds value. + item.expire = gtime.TimestampMilli() + p.TTL.Nanoseconds()/1000000 } p.list.PushBack(item) return nil diff --git a/os/glog/glog_logger_rotate.go b/os/glog/glog_logger_rotate.go index e61d8a952..0dc853640 100644 --- a/os/glog/glog_logger_rotate.go +++ b/os/glog/glog_logger_rotate.go @@ -141,7 +141,9 @@ func (l *Logger) rotateChecks() { // Expiration checks. if l.config.RotateExpire > 0 { nowTimestampMilli := gtime.TimestampMilli() - expireMillisecond := l.config.RotateExpire.Milliseconds() + // As for Golang version <= 1.13, there's no method Milliseconds for time.Duration. + // So we need calculate the milliseconds using its nanoseconds value. + expireMillisecond := l.config.RotateExpire.Nanoseconds() / 1000000 for _, array := range backupFilesMap { array.Iterator(func(_ int, v interface{}) bool { path := v.(string)