internal/gofix and fix error wrapping (#76)

This commit is contained in:
T. von Dein
2026-07-07 10:41:34 +02:00
parent f10366dbde
commit b8e0ee074c
28 changed files with 109 additions and 119 deletions

View File

@@ -22,6 +22,7 @@ import (
"errors"
"fmt"
"log/slog"
"maps"
"strconv"
"strings"
@@ -37,7 +38,7 @@ func IndexTemplateList(conf *cfg.Config) error {
Do(context.Background())
if err != nil {
return fmt.Errorf("failed to get index templates: %s", esErrorString(err))
return fmt.Errorf("failed to get index templates: %w", esErrorString(err))
}
slog.Debug("res", "index templates", res)
@@ -64,7 +65,7 @@ func IndexTemplateShow(conf *cfg.Config, tplname string) error {
Do(context.Background())
if err != nil {
return fmt.Errorf("failed to get index template: %s", esErrorString(err))
return fmt.Errorf("failed to get index template: %w", esErrorString(err))
}
slog.Debug("res", "index template", res)
@@ -225,7 +226,7 @@ func IndexTemplateCreate(conf *cfg.Config, name string, mappings []string) error
_, err := create.Do(context.Background())
if err != nil {
return fmt.Errorf("failed to create index template: %s", esErrorString(err))
return fmt.Errorf("failed to create index template: %w", esErrorString(err))
}
return nil
@@ -242,7 +243,7 @@ func IndexTemplateModify(conf *cfg.Config, name string, mappings []string) error
Do(context.Background())
if err != nil {
return fmt.Errorf("failed to get index template: %s", esErrorString(err))
return fmt.Errorf("failed to get index template: %w", esErrorString(err))
}
slog.Debug("res", "index template", res)
@@ -336,7 +337,7 @@ func IndexTemplateModify(conf *cfg.Config, name string, mappings []string) error
_, err = modify.Do(context.Background())
if err != nil {
return fmt.Errorf("failed to modify index template: %s", esErrorString(err))
return fmt.Errorf("failed to modify index template: %w", esErrorString(err))
}
if conf.Rollover {
@@ -352,7 +353,7 @@ func IndexTemplateDelete(conf *cfg.Config, name string) error {
_, err := conf.DefaultCluster.ES().Indices.DeleteIndexTemplate(name).
Do(context.Background())
if err != nil {
return fmt.Errorf("failed to delete index template: %s", esErrorString(err))
return fmt.Errorf("failed to delete index template: %w", esErrorString(err))
}
return nil
@@ -367,7 +368,7 @@ func rolloverAliasIndexTemplate(conf *cfg.Config, name string) error {
Do(context.Background())
if err != nil {
return fmt.Errorf("failed to get index template: %s", esErrorString(err))
return fmt.Errorf("failed to get index template: %w", esErrorString(err))
}
slog.Debug("res", "index template", res)
@@ -384,7 +385,7 @@ func rolloverAliasIndexTemplate(conf *cfg.Config, name string) error {
res, err := conf.DefaultCluster.ES().Indices.ResolveIndex(pattern).
Do(context.Background())
if err != nil {
return fmt.Errorf("failed to resolve index pattern: %s", esErrorString(err))
return fmt.Errorf("failed to resolve index pattern: %w", esErrorString(err))
}
for _, index := range res.Indices {
@@ -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, ":")