From 24038e36f75330106473187efd161244be9a139b Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Tue, 7 Jul 2026 09:22:18 +0200 Subject: [PATCH] go fix'd --- cmd/utilities.go | 2 +- go.mod | 2 +- pkg/es/cluster.go | 6 ++---- pkg/es/errors.go | 7 ++++--- pkg/es/ilm_forecast.go | 8 ++------ pkg/es/index_template.go | 5 ++--- pkg/printer/pager.go | 7 ------- 7 files changed, 12 insertions(+), 25 deletions(-) diff --git a/cmd/utilities.go b/cmd/utilities.go index 85702eb..c8efb97 100644 --- a/cmd/utilities.go +++ b/cmd/utilities.go @@ -26,7 +26,7 @@ import ( func addReference(ref string) string { indentedRef := []string{} - for _, line := range strings.Split(ref, "\n") { + for line := range strings.SplitSeq(ref, "\n") { indentedRef = append(indentedRef, " "+line) } return fmt.Sprintf("%s\nREFERENCE:\n%s\n", diff --git a/go.mod b/go.mod index 152498b..a24f5bd 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ // along with this program. If not, see . module codeberg.org/scip/esctl -go 1.25.8 +go 1.26.4 require ( github.com/MichaelMure/go-term-markdown v0.1.4 diff --git a/pkg/es/cluster.go b/pkg/es/cluster.go index ac8904b..178af8b 100644 --- a/pkg/es/cluster.go +++ b/pkg/es/cluster.go @@ -44,16 +44,14 @@ func ClusterList(conf *cfg.Config) error { // check endpoints in parallel to speed things up for name, cluster := range conf.Clusters { - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { online, err := cluster.IsReachable() mu.Lock() reachable[name] = clusterReachable{reachable: online, err: err} mu.Unlock() - }() + }) } wg.Wait() diff --git a/pkg/es/errors.go b/pkg/es/errors.go index 7cda3b2..6383fa6 100644 --- a/pkg/es/errors.go +++ b/pkg/es/errors.go @@ -18,6 +18,7 @@ package es import ( "fmt" + "strings" "github.com/elastic/go-elasticsearch/v9/typedapi/types" ) @@ -27,14 +28,14 @@ func esErrorString(err error) string { switch e := err.(type) { case *types.ElasticsearchError: - causes := "" + var causes strings.Builder for _, cause := range e.ErrorCause.RootCause { - causes += fmt.Sprintf("%s\n", *cause.Reason) + causes.WriteString(fmt.Sprintf("%s\n", *cause.Reason)) } if e.ErrorCause.Reason != nil { - msg = *e.ErrorCause.Reason + ": " + causes + msg = *e.ErrorCause.Reason + ": " + causes.String() } else { msg = fmt.Sprintf("http status %d: ", e.Status) } diff --git a/pkg/es/ilm_forecast.go b/pkg/es/ilm_forecast.go index 63d9faa..aaadd2f 100644 --- a/pkg/es/ilm_forecast.go +++ b/pkg/es/ilm_forecast.go @@ -157,11 +157,7 @@ func IlmForecastShow(conf *cfg.Config) error { var toBeFreed int64 = 0 for _, phase := range phaseData { - age := virtualAge(&phase) - - if age < phase.age { - age = phase.age - } + age := max(virtualAge(&phase), phase.age) if age+within >= phase.minage { toBeFreed += phase.size @@ -200,7 +196,7 @@ func getIlmPhaseData(conf *cfg.Config) ([]PhaseData, error) { var indicesres *indices.Response var ilmpolicies getlifecycle.Response - for i := 0; i < 3; i++ { + for range 3 { r := <-responses if r.error != nil { diff --git a/pkg/es/index_template.go b/pkg/es/index_template.go index 55a546f..3a0ecec 100644 --- a/pkg/es/index_template.go +++ b/pkg/es/index_template.go @@ -22,6 +22,7 @@ import ( "errors" "fmt" "log/slog" + "maps" "strconv" "strings" @@ -448,9 +449,7 @@ func modMappings(mappings []string) (types.TypeMappingVariant, error) { func modMeta(conf *cfg.Config, meta types.Metadata) (map[string]json.RawMessage, error) { metadata := map[string]json.RawMessage{} - for key, value := range meta { - metadata[key] = value - } + maps.Copy(metadata, meta) for _, meta := range conf.Meta { parts := strings.Split(meta, ":") diff --git a/pkg/printer/pager.go b/pkg/printer/pager.go index ee8e6a3..037cc3d 100644 --- a/pkg/printer/pager.go +++ b/pkg/printer/pager.go @@ -115,13 +115,6 @@ func (m model) footerView() string { return lipgloss.JoinHorizontal(lipgloss.Center, line, info) } -func max(a, b int) int { - if a > b { - return a - } - return b -} - func Pager(title, message string) { p := tea.NewProgram( model{content: message, title: title},