Skip to content

Commit

Permalink
fix: lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
thoas committed Dec 23, 2020
1 parent fb35bab commit 511289d
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 20 deletions.
62 changes: 62 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
linters-settings:
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- whyNoLint
- wrapperFunc
- hugeParam
golint:
min-confidence: 0
govet:
check-shadowing: false
nolintlint:
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped

# See explanation of linters at https://golangci-lint.run/usage/linters/
linters:
disable-all: true
enable:
- gocritic
- bodyclose
- deadcode
- dogsled
- errcheck
- golint
- goprintffuncname
- interfacer
- gosimple
- govet
- ineffassign
- nakedret
- nolintlint
- rowserrcheck
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unused
- varcheck
- whitespace
- unparam

run:
timeout: 5m

skip-dirs:
- client
- ui
- vendor
- node_modules

1 change: 0 additions & 1 deletion cmd/mover/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func main() {
logger, _ = zap.NewDevelopment()
} else {
logger, _ = zap.NewProduction()

}
// nolint:errcheck
defer logger.Sync()
Expand Down
6 changes: 3 additions & 3 deletions dialect/dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ func (c Columns) Get(name string) Column {
return Column{}
}

func (a Columns) Len() int { return len(a) }
func (a Columns) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a Columns) Less(i, j int) bool { return a[i].Position < a[j].Position }
func (c Columns) Len() int { return len(c) }
func (c Columns) Swap(i, j int) { c[i], c[j] = c[j], c[i] }
func (c Columns) Less(i, j int) bool { return c[i].Position < c[j].Position }

// Column contains the definition of a column table.
type Column struct {
Expand Down
7 changes: 3 additions & 4 deletions dialect/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ func (d *PGDialect) ForeignKeys(ctx context.Context, tableName string) (dialect.
ReferencedTableName: matches[3],
ReferencedColumnName: matches[4],
}

}

return foreignKeys, nil
Expand Down Expand Up @@ -440,13 +439,13 @@ func (d *PGDialect) getTableOID(ctx context.Context, tableName string) (int64, e
return 0, fmt.Errorf("unable to retrieve table %s oid: %w", tableName, err)
}

val, err := result.Value()
raw, err := result.Value()
if err != nil {
return 0, fmt.Errorf("unable to retrieve table %s oid from driver value: %w", tableName, err)
}

switch val := val.(type) {
case int64:
val, ok := raw.(int64)
if ok {
return val, nil
}

Expand Down
12 changes: 5 additions & 7 deletions etl/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import (

lk "github.com/ulule/loukoum/v3"
"github.com/ulule/mover/config"
"github.com/ulule/mover/dialect"
dialectpkg "github.com/ulule/mover/dialect"
"github.com/ulule/mover/dialect/postgres"
)

// copySchemaTables copies tables from database to schema configuration.
func copySchemaTables(schema []config.Schema, tables []dialect.Table) map[string]config.Schema {
func copySchemaTables(schema []config.Schema, tables []dialectpkg.Table) map[string]config.Schema {
schemas := make(map[string]config.Schema, len(tables))
for i := range tables {
tableName := tables[i].Name
Expand All @@ -28,7 +28,6 @@ func copySchemaTables(schema []config.Schema, tables []dialect.Table) map[string
found = true
schema[j].Table = tables[i]
schemas[tableName] = schema[j]

}
}

Expand All @@ -54,7 +53,7 @@ func copySchemaTables(schema []config.Schema, tables []dialect.Table) map[string
// Engine extracts and loads data from database with specific dialect.
type Engine struct {
schema map[string]config.Schema
dialect dialect.Dialect
dialect dialectpkg.Dialect
config config.Config
logger *zap.Logger
}
Expand Down Expand Up @@ -88,7 +87,7 @@ func NewEngine(ctx context.Context, cfg config.Config, dsn string, logger *zap.L
}

// Describe returns a table from its name.
func (e *Engine) Describe(ctx context.Context, tableName string) (dialect.Table, error) {
func (e *Engine) Describe(ctx context.Context, tableName string) (dialectpkg.Table, error) {
schema, ok := e.schema[tableName]
if !ok {
return schema.Table, fmt.Errorf("table %s does not exist", tableName)
Expand All @@ -103,7 +102,7 @@ func (e *Engine) Load(ctx context.Context, outputPath string) error {
}

// Extract extracts data to an output directory with a table name and its query.
func (e *Engine) Extract(ctx context.Context, outputPath string, tableName string, query string) error {
func (e *Engine) Extract(ctx context.Context, outputPath, tableName, query string) error {
extractor := e.newExtractor()

cache, err := extractor.Handle(ctx, e.schema[tableName], query)
Expand All @@ -125,7 +124,6 @@ func (e *Engine) Extract(ctx context.Context, outputPath string, tableName strin
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
Expand Down
10 changes: 6 additions & 4 deletions etl/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ type (
}
)

func depthF(depth int, msg string, args ...interface{}) string {
return strings.Repeat("\t", depth+1) + fmt.Sprintf(msg, args...)
func depthF(depth int, msg string) string {
return strings.Repeat("\t", depth+1) + msg
}

func (e *extractor) handleReferenceKeys(ctx context.Context, depth int, table dialect.Table, row map[string]interface{}) error {
Expand All @@ -48,8 +48,9 @@ func (e *extractor) handleReferenceKeys(ctx context.Context, depth int, table di
}
}

for _, referenceKey := range referenceKeys {
for i := range referenceKeys {
value := row[primaryKey.Name]
referenceKey := referenceKeys[i]

query, args := lk.Select("*").
From(referenceKey.Table.Name).
Expand All @@ -64,7 +65,8 @@ func (e *extractor) handleReferenceKeys(ctx context.Context, depth int, table di
}
}

for _, query := range schema.Queries {
for i := range schema.Queries {
query := schema.Queries[i]
exec := replaceVar(query.Query, row)
e.logger.Debug(depthF(depth+1, "Execute query"),
zap.String("query", exec))
Expand Down
2 changes: 1 addition & 1 deletion etl/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func downloadFiles(ctx context.Context, filenames []string, outputPath string, c
return nil
}

func downloadFile(absoluteURL string, outputDir string) error {
func downloadFile(absoluteURL, outputDir string) error {
res, err := http.Get(absoluteURL)
if err != nil {
return fmt.Errorf("unable to retrieve %s: %w", absoluteURL, err)
Expand Down

0 comments on commit 511289d

Please sign in to comment.