diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 41e66a23..375d7326 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -1,4 +1,4 @@ -name: Golangci Lint Check +name: Golangci-Lint Check on: push: @@ -20,12 +20,49 @@ on: - ".github/dependabot.yml" jobs: - golangci-lint: + generate-matrix: runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + steps: + - name: Fetch Repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - id: set-matrix + run: | + # Determine the base and head commits for diff based on the event type + BASE_SHA="${{ github.event.pull_request.base.sha || github.event.before }}" + HEAD_SHA="${{ github.event.pull_request.head.sha || github.event.after }}" + + # Extract directories from changed files, only include those with go.mod files + GO_MOD_DIRECTORIES=() + FILES=$(git diff --name-only $BASE_SHA $HEAD_SHA | grep -vE '/\.') + DIRECTORIES=$(echo "$FILES" | xargs -L1 dirname | sort -u) + + for dir in $DIRECTORIES; do + if [[ -f "$dir/go.mod" ]]; then + GO_MOD_DIRECTORIES+=("$dir") + fi + done + + # Export the JSON array + JSON_ARRAY=$(printf '%s\n' "${GO_MOD_DIRECTORIES[@]}" | jq -R -s -c 'split("\n")[:-1]') + echo "matrix=${JSON_ARRAY}" >> $GITHUB_OUTPUT + + lint: + needs: generate-matrix + runs-on: ubuntu-latest + strategy: + matrix: + modules: ${{fromJson(needs.generate-matrix.outputs.matrix)}} steps: - name: Fetch Repository uses: actions/checkout@v4 - name: Run golangci-lint uses: reviewdog/action-golangci-lint@v2 with: - golangci_lint_flags: "--tests=false" + golangci_lint_flags: "--tests=false --timeout=5m" + workdir: ${{ matrix.modules }} + fail_on_error: true + filter_mode: nofilter diff --git a/azureblob/azureblob.go b/azureblob/azureblob.go index 47e36bee..cae22a61 100644 --- a/azureblob/azureblob.go +++ b/azureblob/azureblob.go @@ -2,7 +2,6 @@ package azureblob import ( "context" - "errors" "fmt" "io" "time" @@ -108,7 +107,7 @@ func (s *Storage) Reset() error { } } if errCounter > 0 { - return errors.New(fmt.Sprintf("%d errors occured while resetting", errCounter)) + return fmt.Errorf("%d errors occured while resetting", errCounter) } return nil } diff --git a/mongodb/mongodb.go b/mongodb/mongodb.go index d4c359bb..4164551f 100644 --- a/mongodb/mongodb.go +++ b/mongodb/mongodb.go @@ -53,18 +53,14 @@ func New(config ...Config) *Storage { } // Set mongo options - opt := options.Client() - opt.ApplyURI(dsn) + opt := options.Client().ApplyURI(dsn) - // Create mongo client - client, err := mongo.NewClient(opt) - if err != nil { - panic(err) - } - - ctx, cancel := context.WithTimeout(context.TODO(), 20*time.Second) + // Create and connect the mongo client in one step + ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) defer cancel() - if err = client.Connect(ctx); err != nil { + + client, err := mongo.Connect(ctx, opt) + if err != nil { panic(err) } diff --git a/mysql/mysql.go b/mysql/mysql.go index b2d86fcf..06509e64 100644 --- a/mysql/mysql.go +++ b/mysql/mysql.go @@ -105,8 +105,6 @@ func New(config ...Config) *Storage { return store } -var noRows = "sql: no rows in result set" - // Get value by key func (s *Storage) Get(key string) ([]byte, error) { if len(key) <= 0 { @@ -136,7 +134,6 @@ func (s *Storage) Get(key string) ([]byte, error) { return data, nil } -// Set key with value // Set key with value func (s *Storage) Set(key string, val []byte, exp time.Duration) error { // Ain't Nobody Got Time For That diff --git a/pebble/pebble.go b/pebble/pebble.go index e59e6e73..e0573199 100644 --- a/pebble/pebble.go +++ b/pebble/pebble.go @@ -130,11 +130,6 @@ func isValid(fp string) bool { return false } - err = os.Remove(fp) // And delete it - - if err != nil { - return false - } - - return true + err = os.Remove(fp) + return err == nil } diff --git a/sqlite3/sqlite3.go b/sqlite3/sqlite3.go index 7070a3b8..0e5f7733 100644 --- a/sqlite3/sqlite3.go +++ b/sqlite3/sqlite3.go @@ -22,8 +22,6 @@ type Storage struct { } var ( - checkSchemaMsg = "The `v` row has an incorrect data type. " + - "It should be BLOB but is instead %s. This will cause encoding-related panics if the DB is not migrated (see https://github.com/gofiber/storage/blob/main/MIGRATE.md)." dropQuery = `DROP TABLE IF EXISTS %s;` initQuery = []string{ `CREATE TABLE IF NOT EXISTS %s (