diff --git a/.github/workflows/backend-tests.yml b/.github/workflows/backend-tests.yml index e96a3c9..6a05087 100644 --- a/.github/workflows/backend-tests.yml +++ b/.github/workflows/backend-tests.yml @@ -25,7 +25,7 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v6 with: - version: v1.54.1 + version: v1.56.1 args: --verbose --timeout=3m skip-cache: true diff --git a/.golangci.yaml b/.golangci.yaml index e4a0f65..0868a99 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -19,12 +19,7 @@ issues: include: # https://golangci-lint.run/usage/configuration/#command-line-options exclude: - - Rollback - - logger.Sync - - pgInstance.Stop - fmt.Printf - - Enter(.*)_(.*) - - Exit(.*)_(.*) linters-settings: goimports: @@ -69,6 +64,10 @@ linters-settings: disabled: true - name: var-naming disabled: true + - name: unchecked-type-assertion + disabled: true + - name: max-control-nesting + disabled: true - name: exported arguments: - "disableStutteringCheck" diff --git a/bin/slash/main.go b/bin/slash/main.go index 5c9d019..1933f89 100644 --- a/bin/slash/main.go +++ b/bin/slash/main.go @@ -13,9 +13,9 @@ import ( "github.com/spf13/viper" "github.com/yourselfhosted/slash/server" + "github.com/yourselfhosted/slash/server/common" "github.com/yourselfhosted/slash/server/metric" "github.com/yourselfhosted/slash/server/profile" - "github.com/yourselfhosted/slash/server/version" "github.com/yourselfhosted/slash/store" "github.com/yourselfhosted/slash/store/db" ) @@ -35,7 +35,7 @@ var ( Data: viper.GetString("data"), DSN: viper.GetString("dsn"), Driver: viper.GetString("driver"), - Version: version.GetCurrentVersion(viper.GetString("mode")), + Version: common.GetCurrentVersion(viper.GetString("mode")), } if err := serverProfile.Validate(); err != nil { panic(err) diff --git a/plugin/idp/oauth2/oauth2_test.go b/plugin/idp/oauth2/oauth2_test.go index f721716..b4a65f9 100644 --- a/plugin/idp/oauth2/oauth2_test.go +++ b/plugin/idp/oauth2/oauth2_test.go @@ -98,7 +98,7 @@ func newMockServer(t *testing.T, code, accessToken string, userinfo []byte) *htt }) require.NoError(t, err) }) - mux.HandleFunc("/oauth2/userinfo", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/oauth2/userinfo", func(w http.ResponseWriter, _ *http.Request) { w.Header().Set("Content-Type", "application/json") _, err := w.Write(userinfo) require.NoError(t, err) diff --git a/server/version/version.go b/server/common/version.go similarity index 98% rename from server/version/version.go rename to server/common/version.go index 5751744..23c01bb 100644 --- a/server/version/version.go +++ b/server/common/version.go @@ -1,4 +1,4 @@ -package version +package common import ( "fmt" diff --git a/server/version/version_test.go b/server/common/version_test.go similarity index 99% rename from server/version/version_test.go rename to server/common/version_test.go index d06d97a..9b03785 100644 --- a/server/version/version_test.go +++ b/server/common/version_test.go @@ -1,4 +1,4 @@ -package version +package common import ( "sort" diff --git a/store/db/postgres/migrator.go b/store/db/postgres/migrator.go index f3b1773..5ff429e 100644 --- a/store/db/postgres/migrator.go +++ b/store/db/postgres/migrator.go @@ -11,7 +11,7 @@ import ( "github.com/pkg/errors" - "github.com/yourselfhosted/slash/server/version" + "github.com/yourselfhosted/slash/server/common" "github.com/yourselfhosted/slash/store" ) @@ -68,7 +68,7 @@ func (d *DB) nonProdMigrate(ctx context.Context) error { } func (d *DB) prodMigrate(ctx context.Context) error { - currentVersion := version.GetCurrentVersion(d.profile.Mode) + currentVersion := common.GetCurrentVersion(d.profile.Mode) migrationHistoryList, err := d.ListMigrationHistories(ctx, &store.FindMigrationHistory{}) // If there is no migration history, we should apply the latest schema. if err != nil || len(migrationHistoryList) == 0 { @@ -94,17 +94,17 @@ func (d *DB) prodMigrate(ctx context.Context) error { for _, migrationHistory := range migrationHistoryList { migrationHistoryVersionList = append(migrationHistoryVersionList, migrationHistory.Version) } - sort.Sort(version.SortVersion(migrationHistoryVersionList)) + sort.Sort(common.SortVersion(migrationHistoryVersionList)) latestMigrationHistoryVersion := migrationHistoryVersionList[len(migrationHistoryVersionList)-1] // If the latest migration history version is greater than or equal to the current version, we will not apply any migration. - if !version.IsVersionGreaterThan(version.GetSchemaVersion(currentVersion), latestMigrationHistoryVersion) { + if !common.IsVersionGreaterThan(common.GetSchemaVersion(currentVersion), latestMigrationHistoryVersion) { return nil } println("start migrate") for _, minorVersion := range getMinorVersionList() { normalizedVersion := minorVersion + ".0" - if version.IsVersionGreaterThan(normalizedVersion, latestMigrationHistoryVersion) && version.IsVersionGreaterOrEqualThan(currentVersion, normalizedVersion) { + if common.IsVersionGreaterThan(normalizedVersion, latestMigrationHistoryVersion) && common.IsVersionGreaterOrEqualThan(currentVersion, normalizedVersion) { println("applying migration for", normalizedVersion) if err := d.applyMigrationForMinorVersion(ctx, minorVersion); err != nil { return errors.Wrap(err, "failed to apply minor version migration") @@ -166,6 +166,6 @@ func getMinorVersionList() []string { panic(err) } - sort.Sort(version.SortVersion(minorVersionList)) + sort.Sort(common.SortVersion(minorVersionList)) return minorVersionList } diff --git a/store/db/sqlite/migrator.go b/store/db/sqlite/migrator.go index cf494e0..893a446 100644 --- a/store/db/sqlite/migrator.go +++ b/store/db/sqlite/migrator.go @@ -12,7 +12,7 @@ import ( "github.com/pkg/errors" - "github.com/yourselfhosted/slash/server/version" + "github.com/yourselfhosted/slash/server/common" "github.com/yourselfhosted/slash/store" ) @@ -24,7 +24,7 @@ var seedFS embed.FS // Migrate applies the latest schema to the database. func (d *DB) Migrate(ctx context.Context) error { - currentVersion := version.GetCurrentVersion(d.profile.Mode) + currentVersion := common.GetCurrentVersion(d.profile.Mode) if d.profile.Mode == "prod" { _, err := os.Stat(d.profile.DSN) if err != nil { @@ -50,7 +50,7 @@ func (d *DB) Migrate(ctx context.Context) error { } // If no migration history, we should apply the latest version migration and upsert the migration history. if len(migrationHistoryList) == 0 { - minorVersion := version.GetMinorVersion(currentVersion) + minorVersion := common.GetMinorVersion(currentVersion) if err := d.applyMigrationForMinorVersion(ctx, minorVersion); err != nil { return errors.Wrapf(err, "failed to apply version %s migration", minorVersion) } @@ -67,10 +67,10 @@ func (d *DB) Migrate(ctx context.Context) error { for _, migrationHistory := range migrationHistoryList { migrationHistoryVersionList = append(migrationHistoryVersionList, migrationHistory.Version) } - sort.Sort(version.SortVersion(migrationHistoryVersionList)) + sort.Sort(common.SortVersion(migrationHistoryVersionList)) latestMigrationHistoryVersion := migrationHistoryVersionList[len(migrationHistoryVersionList)-1] - if version.IsVersionGreaterThan(version.GetSchemaVersion(currentVersion), latestMigrationHistoryVersion) { + if common.IsVersionGreaterThan(common.GetSchemaVersion(currentVersion), latestMigrationHistoryVersion) { minorVersionList := getMinorVersionList() // backup the raw database file before migration rawBytes, err := os.ReadFile(d.profile.DSN) @@ -85,7 +85,7 @@ func (d *DB) Migrate(ctx context.Context) error { println("start migrate") for _, minorVersion := range minorVersionList { normalizedVersion := minorVersion + ".0" - if version.IsVersionGreaterThan(normalizedVersion, latestMigrationHistoryVersion) && version.IsVersionGreaterOrEqualThan(currentVersion, normalizedVersion) { + if common.IsVersionGreaterThan(normalizedVersion, latestMigrationHistoryVersion) && common.IsVersionGreaterOrEqualThan(currentVersion, normalizedVersion) { println("applying migration for", normalizedVersion) if err := d.applyMigrationForMinorVersion(ctx, minorVersion); err != nil { return errors.Wrap(err, "failed to apply minor version migration") @@ -228,6 +228,6 @@ func getMinorVersionList() []string { panic(err) } - sort.Sort(version.SortVersion(minorVersionList)) + sort.Sort(common.SortVersion(minorVersionList)) return minorVersionList } diff --git a/test/test.go b/test/test.go index 4ab33d6..83b089a 100644 --- a/test/test.go +++ b/test/test.go @@ -8,8 +8,8 @@ import ( "github.com/joho/godotenv" + "github.com/yourselfhosted/slash/server/common" "github.com/yourselfhosted/slash/server/profile" - "github.com/yourselfhosted/slash/server/version" ) func getUnusedPort() int { @@ -45,7 +45,7 @@ func GetTestingProfile(t *testing.T) *profile.Profile { Data: dir, DSN: dsn, Driver: driver, - Version: version.GetCurrentVersion(mode), + Version: common.GetCurrentVersion(mode), } }