From bf82328c36ec034d572c765f2fa1494096b1306d Mon Sep 17 00:00:00 2001 From: Florent Messa Date: Fri, 19 Jan 2024 16:08:10 +0100 Subject: [PATCH] fix: move extra export to bottom --- cmd/mover/main.go | 2 +- etl/engine.go | 18 +++++++++--------- etl/loader.go | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cmd/mover/main.go b/cmd/mover/main.go index a7de72a..90e70da 100644 --- a/cmd/mover/main.go +++ b/cmd/mover/main.go @@ -39,7 +39,7 @@ func main() { } else { logger, _ = zap.NewProduction() } - // nolint:errcheck + //nolint:errcheck defer logger.Sync() var cfg config.Config diff --git a/etl/engine.go b/etl/engine.go index b305c59..57f4174 100644 --- a/etl/engine.go +++ b/etl/engine.go @@ -4,7 +4,7 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "os" "path" "strings" @@ -114,22 +114,22 @@ func (e *Engine) Extract(ctx context.Context, outputPath, query string) error { return fmt.Errorf("unable to extract %s (query %s): %w", tableName, query, err) } + for tableName := range cache { + if err := e.extract(ctx, outputPath, e.schema[tableName], cache[tableName]); err != nil { + return fmt.Errorf("unable to extract rows from table %s: %w", tableName, err) + } + } + for i := range e.config.Extra { tableName := e.config.Extra[i].TableName query, _ := lk.Select(lk.Raw("*")). From(tableName).Query() - cache, err = extractor.Handle(ctx, e.schema[tableName], query) + _, err = extractor.Handle(ctx, e.schema[tableName], query) if err != nil { return fmt.Errorf("unable to extract %s (query %s): %w", tableName, query, err) } } - for tableName := range cache { - if err := e.extract(ctx, outputPath, e.schema[tableName], cache[tableName]); err != nil { - return fmt.Errorf("unable to extract rows from table %s: %w", tableName, err) - } - } - return nil } @@ -155,7 +155,7 @@ func (e *Engine) extract(ctx context.Context, outputPath string, schema config.S } filePath := path.Join(outputPath, table.Name+extensionFormat) - if err := ioutil.WriteFile(filePath, output, 0644); err != nil { + if err := os.WriteFile(filePath, output, 0644); err != nil { return fmt.Errorf("unable to write JSON output to %s: %w", filePath, err) } diff --git a/etl/loader.go b/etl/loader.go index 528fd6d..9ee2781 100644 --- a/etl/loader.go +++ b/etl/loader.go @@ -4,7 +4,7 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "io" "os" "path/filepath" "strings" @@ -58,7 +58,7 @@ func (l *loader) loadFile(ctx context.Context, filePath string) error { } defer file.Close() - content, err := ioutil.ReadAll(file) + content, err := io.ReadAll(file) if err != nil { return fmt.Errorf("unable to read file %s: %w", filePath, err) }