From 368c936c321cea2f8669b75e712609b13d71629a Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Tue, 27 Aug 2024 18:58:46 +0200 Subject: [PATCH] Lint: Fix linter errors Signed-off-by: Knut Ahlers --- api.go | 2 +- internal/badge/badge.go | 2 +- internal/database/db.go | 4 +++- internal/fetcher/html.go | 2 +- internal/fetcher/json.go | 2 +- scheduler.go | 9 +++------ 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/api.go b/api.go index 084812a..f4a889b 100644 --- a/api.go +++ b/api.go @@ -136,7 +136,7 @@ func handleCatalogGetVersion(w http.ResponseWriter, r *http.Request) { } w.Header().Set("Content-Type", "text/plain") - fmt.Fprint(w, cm.CurrentVersion) + fmt.Fprint(w, cm.CurrentVersion) //nolint:errcheck } func handleCatalogList(w http.ResponseWriter, _ *http.Request) { diff --git a/internal/badge/badge.go b/internal/badge/badge.go index 0ffd589..4f16c61 100644 --- a/internal/badge/badge.go +++ b/internal/badge/badge.go @@ -46,7 +46,7 @@ func Create(title, text, color string) []byte { titleW, _ := calculateTextWidth(title) textW, _ := calculateTextWidth(text) - width := titleW + textW + 4*xSpacing //nolint:gomnd + width := titleW + textW + 4*xSpacing //nolint:mnd t, _ := assets.ReadFile("badge.svg.tpl") tpl, _ := template.New("svg").Parse(string(t)) diff --git a/internal/database/db.go b/internal/database/db.go index 3168c17..4972fd8 100644 --- a/internal/database/db.go +++ b/internal/database/db.go @@ -118,4 +118,6 @@ func (c Client) initDB() error { return nil } -func (l logwrap) Printf(f string, v ...interface{}) { fmt.Fprintf(l.l, f, v...) } +func (l logwrap) Printf(f string, v ...interface{}) { + fmt.Fprintf(l.l, f, v...) //nolint:errcheck +} diff --git a/internal/fetcher/html.go b/internal/fetcher/html.go index 88eb0ad..12d4e0f 100644 --- a/internal/fetcher/html.go +++ b/internal/fetcher/html.go @@ -53,7 +53,7 @@ func (HTMLFetcher) FetchVersion(_ context.Context, attrs *fieldcollection.FieldC } match := regexp.MustCompile(attrs.MustString("regex", &htmlFetcherDefaultRegex)).FindStringSubmatch(node.Data) - if len(match) < 2 { //nolint:gomnd // Simple count of fields, no need for constant + if len(match) < 2 { //nolint:mnd // Simple count of fields, no need for constant return "", time.Time{}, errors.New("regular expression did not yield version") } diff --git a/internal/fetcher/json.go b/internal/fetcher/json.go index 206d4e1..58ea34e 100644 --- a/internal/fetcher/json.go +++ b/internal/fetcher/json.go @@ -97,7 +97,7 @@ func (JSONFetcher) FetchVersion(ctx context.Context, attrs *fieldcollection.Fiel } match := regexp.MustCompile(attrs.MustString("regex", &jsonFetcherDefaultRegex)).FindStringSubmatch(node.Data) - if len(match) < 2 { //nolint:gomnd // Simple count of fields, no need for constant + if len(match) < 2 { //nolint:mnd // Simple count of fields, no need for constant return "", time.Time{}, errors.New("regular expression did not yield version") } diff --git a/scheduler.go b/scheduler.go index 9bfec7b..eb546a4 100644 --- a/scheduler.go +++ b/scheduler.go @@ -3,7 +3,6 @@ package main import ( "context" "crypto/md5" //#nosec G501 // Used to derive a static jitter checksum, not cryptographically - "fmt" "math" "strings" "time" @@ -120,12 +119,10 @@ func nextCheckTime(ce *database.CatalogEntry, lastCheck *time.Time) time.Time { return time.Now() } - hash := md5.New() //#nosec G401 // Used to derive a static jitter checksum, not cryptographically - fmt.Fprint(hash, ce.Key()) - var jitter int64 - for i, c := range hash.Sum(nil) { - jitter += int64(c) * int64(math.Pow(10, float64(i))) //nolint:gomnd // No need for constant here + //#nosec G401 // Used to derive a static jitter checksum, not cryptographically + for i, c := range md5.Sum([]byte(ce.Key())) { + jitter += int64(c) * int64(math.Pow(10, float64(i))) //nolint:mnd // No need for constant here } next := lastCheck.