staticcheck: Use time.Since, time.Until

5 views
Skip to first unread message

nor...@perkeep.org

unread,
Mar 13, 2022, 4:41:21 PM3/13/22
to camlistor...@googlegroups.com


https://github.com/perkeep/perkeep/commit/8df8a3657d46a8cff055fed83e88451c544e262c

commit 8df8a3657d46a8cff055fed83e88451c544e262c
Author: Tamás Gulácsi <T.Gu...@unosoft.hu>
Date: Fri Sep 10 14:15:01 2021 +0200

staticcheck: Use time.Since, time.Until

checks S1012,S1024

Use global staticcheck.conf

diff --git a/.github/workflows/tests-lint.yaml b/.github/workflows/tests-lint.yaml
index f943f92..0fa4192 100644
--- a/.github/workflows/tests-lint.yaml
+++ b/.github/workflows/tests-lint.yaml
@@ -35,7 +35,7 @@ jobs:
run: go vet ./...

- name: Run staticcheck
- run: go run honnef.co/go/tools/cmd/staticcheck -checks=U1000 ./...
+ run: go run honnef.co/go/tools/cmd/staticcheck ./...

- name: Check for env vars documentation
run: go run dev/envvardoc/envvardoc.go
diff --git a/Makefile b/Makefile
index 5583734..7e8e53a 100644
--- a/Makefile
+++ b/Makefile
@@ -12,6 +12,9 @@ presubmit: fmt
fmt:
go fmt perkeep.org/cmd/... perkeep.org/dev/... perkeep.org/misc/... perkeep.org/pkg/... perkeep.org/server/... perkeep.org/internal/...

+lint:
+ go run honnef.co/go/tools/cmd/staticcheck ./...
+
dockerbuild:
docker build --tag=gcr.io/perkeep-containers/perkeep:latest .

diff --git a/pkg/importer/importer.go b/pkg/importer/importer.go
index 708c7de..af298ed 100644
--- a/pkg/importer/importer.go
+++ b/pkg/importer/importer.go
@@ -732,7 +732,7 @@ func (ia *importerAcct) maybeStart() {
if ia.lastRunDone.After(time.Now().Add(-duration)) {
// Kick off long poller wait if supported.
if lp, ok := ia.im.impl.(LongPoller); ok {
- sleepFor := ia.lastRunDone.Add(duration).Sub(time.Now())
+ sleepFor := time.Until(ia.lastRunDone.Add(duration))
sleepCtx, cancel := context.WithTimeout(context.Background(), sleepFor)
log.Printf("%v ran recently enough. Sleeping for %v.", ia, sleepFor)
timer := time.AfterFunc(sleepFor, ia.maybeStart)
diff --git a/pkg/server/share.go b/pkg/server/share.go
index e9e4a12..4e6a653 100644
--- a/pkg/server/share.go
+++ b/pkg/server/share.go
@@ -178,7 +178,7 @@ func (h *shareHandler) handleGetViaSharing(rw http.ResponseWriter, req *http.Req
if !viaPathOkay {
// Insert a delay, to hide timing attacks probing
// for the existence of blobs.
- sleep := fetchFailureDelay - (time.Now().Sub(startTime))
+ sleep := fetchFailureDelay - time.Since(startTime)
timeSleep(sleep)
}
}()
diff --git a/pkg/server/sync.go b/pkg/server/sync.go
index 6375497..6a5a5cc 100644
--- a/pkg/server/sync.go
+++ b/pkg/server/sync.go
@@ -321,7 +321,7 @@ func (sh *SyncHandler) currentStatus() syncStatus {
defer sh.mu.Unlock()
ago := 0
if !sh.recentCopyTime.IsZero() {
- ago = int(time.Now().Sub(sh.recentCopyTime).Seconds())
+ ago = int(time.Since(sh.recentCopyTime) / time.Second)
}
return syncStatus{
sh: sh,
diff --git a/staticcheck.conf b/staticcheck.conf
new file mode 100644
index 0000000..77ac7bd
--- /dev/null
+++ b/staticcheck.conf
@@ -0,0 +1,5 @@
+checks = [
+ "U1000",
+ "S1012",
+ "S1024",
+]
diff --git a/website/pk-web/pkweb.go b/website/pk-web/pkweb.go
index 14f37d8..0fe3f5c 100644
--- a/website/pk-web/pkweb.go
+++ b/website/pk-web/pkweb.go
@@ -1185,7 +1185,7 @@ func ipHandler(w http.ResponseWriter, r *http.Request) {
var startTime = time.Now()

func uptimeHandler(w http.ResponseWriter, r *http.Request) {
- fmt.Fprintf(w, "%v", time.Now().Sub(startTime))
+ fmt.Fprintf(w, "%v", time.Since(startTime))
}

const (
Reply all
Reply to author
Forward
0 new messages