device, ratelimiter: replace uses of time.Now().Sub() with time.Since()

Simplification found by staticcheck:

$ staticcheck ./... | grep S1012
device/cookie.go:90:5: should use time.Since instead of time.Now().Sub (S1012)
device/cookie.go:127:5: should use time.Since instead of time.Now().Sub (S1012)
device/cookie.go:242:5: should use time.Since instead of time.Now().Sub (S1012)
device/noise-protocol.go:304:13: should use time.Since instead of time.Now().Sub (S1012)
device/receive.go:82:46: should use time.Since instead of time.Now().Sub (S1012)
device/send.go:132:5: should use time.Since instead of time.Now().Sub (S1012)
device/send.go:139:5: should use time.Since instead of time.Now().Sub (S1012)
device/send.go:235:59: should use time.Since instead of time.Now().Sub (S1012)
device/send.go:393:9: should use time.Since instead of time.Now().Sub (S1012)
ratelimiter/ratelimiter.go:79:10: should use time.Since instead of time.Now().Sub (S1012)
ratelimiter/ratelimiter.go:87:10: should use time.Since instead of time.Now().Sub (S1012)

Change applied using:

$ find . -type f -name "*.go" -exec sed -i "s/Now().Sub(/Since(/g" {} \;

Signed-off-by: Matt Layher <mdlayher@gmail.com>
This commit is contained in:
Matt Layher
2019-06-03 15:46:46 -04:00
committed by Jason A. Donenfeld
parent 80ef2a42e6
commit 18b6627f33
5 changed files with 11 additions and 11 deletions

View File

@@ -76,7 +76,7 @@ func (rate *Ratelimiter) Init() {
for key, entry := range rate.tableIPv4 {
entry.Lock()
if time.Now().Sub(entry.lastTime) > garbageCollectTime {
if time.Since(entry.lastTime) > garbageCollectTime {
delete(rate.tableIPv4, key)
}
entry.Unlock()
@@ -84,7 +84,7 @@ func (rate *Ratelimiter) Init() {
for key, entry := range rate.tableIPv6 {
entry.Lock()
if time.Now().Sub(entry.lastTime) > garbageCollectTime {
if time.Since(entry.lastTime) > garbageCollectTime {
delete(rate.tableIPv6, key)
}
entry.Unlock()