From b30d3e568c7057b50f6900d9b1662f4c89a65470 Mon Sep 17 00:00:00 2001 From: karamaru-alpha Date: Sat, 28 Oct 2023 14:16:58 +0900 Subject: [PATCH] Fix lint/go errors (gocritic) Signed-off-by: karamaru-alpha --- pkg/app/ops/handler/handler.go | 2 +- pkg/app/server/httpapi/httpapimetrics/delegator.go | 6 +++--- pkg/cli/cmd.go | 2 +- pkg/config/control_plane.go | 2 +- pkg/datastore/mysql/query.go | 4 ++-- pkg/filematcher/filematcher.go | 11 ++++++----- pkg/insight/insightmetrics/metrics.go | 2 +- 7 files changed, 15 insertions(+), 14 deletions(-) diff --git a/pkg/app/ops/handler/handler.go b/pkg/app/ops/handler/handler.go index 714c389e1c..757b643636 100644 --- a/pkg/app/ops/handler/handler.go +++ b/pkg/app/ops/handler/handler.go @@ -238,7 +238,7 @@ func groupApplicationCounts(counts []model.InsightApplicationCount) (total int, for _, c := range counts { total += int(c.Count) kind := c.Labels[model.InsightApplicationCountLabelKey_KIND.String()] - groups[kind] = groups[kind] + int(c.Count) + groups[kind] += int(c.Count) } return } diff --git a/pkg/app/server/httpapi/httpapimetrics/delegator.go b/pkg/app/server/httpapi/httpapimetrics/delegator.go index 9caee5eec5..ac976ef5e6 100644 --- a/pkg/app/server/httpapi/httpapimetrics/delegator.go +++ b/pkg/app/server/httpapi/httpapimetrics/delegator.go @@ -100,7 +100,7 @@ type pusherDelegator struct{ *responseWriterDelegator } func (d closeNotifierDelegator) CloseNotify() <-chan bool { //lint:ignore SA1019 http.CloseNotifier is deprecated but we don't want to - //remove support from client_golang yet. + // remove support from client_golang yet. return d.ResponseWriter.(http.CloseNotifier).CloseNotify() } func (d flusherDelegator) Flush() { @@ -278,7 +278,7 @@ func init() { http.Flusher }{d, pusherDelegator{d}, hijackerDelegator{d}, flusherDelegator{d}} } - pickDelegator[pusher+hijacker+flusher+closeNotifier] = func(d *responseWriterDelegator) delegator { //23 + pickDelegator[pusher+hijacker+flusher+closeNotifier] = func(d *responseWriterDelegator) delegator { // 23 return struct { *responseWriterDelegator http.Pusher @@ -365,7 +365,7 @@ func newDelegator(w http.ResponseWriter, observeWriteHeaderFunc func(int)) deleg id := 0 //lint:ignore SA1019 http.CloseNotifier is deprecated but we don't want to - //remove support from client_golang yet. + // remove support from client_golang yet. if _, ok := w.(http.CloseNotifier); ok { id += closeNotifier } diff --git a/pkg/cli/cmd.go b/pkg/cli/cmd.go index 5c9741c707..49c7360ba0 100644 --- a/pkg/cli/cmd.go +++ b/pkg/cli/cmd.go @@ -192,5 +192,5 @@ func (t Input) CustomMetricsHandlerFor(reg prometheus.Gatherer, mb MetricsBuilde } func extractServiceName(cmd *cobra.Command) string { - return strings.Replace(cmd.CommandPath(), " ", ".", -1) + return strings.ReplaceAll(cmd.CommandPath(), " ", ".") } diff --git a/pkg/config/control_plane.go b/pkg/config/control_plane.go index 1dd9a61c93..b4bcdab52a 100644 --- a/pkg/config/control_plane.go +++ b/pkg/config/control_plane.go @@ -281,7 +281,7 @@ func (f *ControlPlaneFileStore) UnmarshalJSON(data []byte) error { } default: // Left comment out for mock response. - //err = fmt.Errorf("unsupported filestore type: %s", f.Type) + // err = fmt.Errorf("unsupported filestore type: %s", f.Type) err = nil } return err diff --git a/pkg/datastore/mysql/query.go b/pkg/datastore/mysql/query.go index da414225e0..ce82db0565 100644 --- a/pkg/datastore/mysql/query.go +++ b/pkg/datastore/mysql/query.go @@ -92,7 +92,7 @@ func buildWhereClause(filters []datastore.ListFilter) (string, error) { conds[i] = fmt.Sprintf("%s %s ?", filter.Field, op) } } - return fmt.Sprintf("WHERE %s", strings.Join(conds[:], " AND ")), nil + return fmt.Sprintf("WHERE %s", strings.Join(conds, " AND ")), nil } func buildPaginationCondition(opts datastore.ListOptions) string { @@ -165,7 +165,7 @@ func buildOrderByClause(orders []datastore.Order) (string, error) { return "", fmt.Errorf("id field is required as ordering field") } - return fmt.Sprintf("ORDER BY %s", strings.Join(conds[:], ", ")), nil + return fmt.Sprintf("ORDER BY %s", strings.Join(conds, ", ")), nil } func buildLimitClause(limit int) string { diff --git a/pkg/filematcher/filematcher.go b/pkg/filematcher/filematcher.go index 6a7caf5edf..f0cd1a1b6c 100644 --- a/pkg/filematcher/filematcher.go +++ b/pkg/filematcher/filematcher.go @@ -184,7 +184,8 @@ func (p *Pattern) regexpString() string { for scan.Peek() != scanner.EOF { ch := scan.Next() - if ch == '*' { + switch ch { + case '*': if scan.Peek() == '*' { // Is some flavor of "**". scan.Next() @@ -207,14 +208,14 @@ func (p *Pattern) regexpString() string { // Is "*" so map it to anything but "/". regStr += "[^" + escSL + "]*" } - } else if ch == '?' { + case '?': // "?" is any char except "/". regStr += "[^" + escSL + "]" - } else if ch == '.' || ch == '$' { + case '.', '$': // Escape some regexp special chars that have no meaning // in golang's filepath.Match. regStr += `\` + string(ch) - } else if ch == '\\' { + case '\\': // Escape next char. Note that a trailing \ in the pattern // will be left alone (but need to escape it). if sl == `\` { @@ -229,7 +230,7 @@ func (p *Pattern) regexpString() string { } else { regStr += `\` } - } else { + default: regStr += string(ch) } } diff --git a/pkg/insight/insightmetrics/metrics.go b/pkg/insight/insightmetrics/metrics.go index 34ce460c75..e46d498c30 100644 --- a/pkg/insight/insightmetrics/metrics.go +++ b/pkg/insight/insightmetrics/metrics.go @@ -100,7 +100,7 @@ func groupApplicationCounts(counts []model.InsightApplicationCount) map[string]i groups := make(map[string]int, len(counts)) for _, c := range counts { kind := c.Labels[model.InsightApplicationCountLabelKey_KIND.String()] - groups[kind] = groups[kind] + int(c.Count) + groups[kind] += int(c.Count) } return groups }