Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: enable more revive linters (part 1) (#1928)

Yilong Lib2cbbb25050d
diff --git a/.golangci.yaml b/.golangci.yaml
index a8a6e00f88..f7c874f153 100644
--- a/.golangci.yaml
+++ b/.golangci.yaml
@@ -30,11 +30,57 @@ run:
linters-settings:
revive:
+ # Default to run all linters so that new rules in the future could automatically be added to the static check.
+ enable-all-rules: true
rules:
- - name: exported
- arguments:
- - checkPrivateReceivers
- - sayRepetitiveInsteadOfStutters
+ # The following rules are too strict and make coding harder. We do not enable them for now.
+ - name: file-header
+ disabled: true
+ - name: line-length-limit
+ disabled: true
+ - name: function-length
+ disabled: true
+ - name: max-public-structs
+ disabled: true
+ - name: function-result-limit
+ disabled: true
+ - name: banned-characters
+ disabled: true
+ - name: argument-limit
+ disabled: true
+ - name: cognitive-complexity
+ disabled: true
+ - name: cyclomatic
+ disabled: true
+ - name: confusing-results
+ disabled: true
+ - name: add-constant
+ disabled: true
+ - name: flag-parameter
+ disabled: true
+ - name: nested-structs
+ disabled: true
+ - name: import-shadowing
+ disabled: true
+ - name: early-return
+ disabled: true
+ # TODO(dragonly): Remove the rules below in the following PRs.
+ - name: unused-parameter
+ disabled: true
+ - name: unused-receiver
+ disabled: true
+ - name: unhandled-error
+ disabled: true
+ - name: if-return
+ disabled: true
+ - name: empty-block
+ disabled: true
+ - name: empty-lines
+ disabled: true
+ - name: confusing-naming
+ disabled: true
+ - name: defer
+ disabled: true
gocritic:
disabled-checks:
- ifElseChain
diff --git a/bin/server/cmd/root.go b/bin/server/cmd/root.go
index 3509ca4aaa..6e57dcc1d6 100644
--- a/bin/server/cmd/root.go
+++ b/bin/server/cmd/root.go
@@ -153,8 +153,7 @@ func checkDataDir() error {
flags.dataDir = strings.TrimRight(flags.dataDir, "/")
if _, err := os.Stat(flags.dataDir); err != nil {
- error := fmt.Errorf("unable to access --data %s, %w", flags.dataDir, err)
- return error
+ return fmt.Errorf("unable to access --data %s, %w", flags.dataDir, err)
}
return nil
diff --git a/common/util.go b/common/util.go
index 58189ba77a..ba8b1d8043 100644
--- a/common/util.go
+++ b/common/util.go
@@ -11,10 +11,10 @@ import (
)
// FindString returns the search index of sorted strings.
-func FindString(strings []string, search string) int {
- sort.Strings(strings)
- i := sort.SearchStrings(strings, search)
- if i == len(strings) {
+func FindString(stringList []string, search string) int {
+ sort.Strings(stringList)
+ i := sort.SearchStrings(stringList, search)
+ if i == len(stringList) {
return -1
}
return i
diff --git a/plugin/advisor/advisor.go b/plugin/advisor/advisor.go
index 625fb26af6..82c7258984 100644
--- a/plugin/advisor/advisor.go
+++ b/plugin/advisor/advisor.go
@@ -37,6 +37,7 @@ func NewStatusBySQLReviewRuleLevel(level SQLReviewRuleLevel) (Status, error) {
}
// Type is the type of advisor.
+// nolint
type Type string
const (
diff --git a/plugin/advisor/fake/fake_advisor.go b/plugin/advisor/fake/fake_advisor.go
index 986b094932..bca5ea86d8 100644
--- a/plugin/advisor/fake/fake_advisor.go
+++ b/plugin/advisor/fake/fake_advisor.go
@@ -19,7 +19,7 @@ type Advisor struct {
}
// Check is a fake advisor check reporting 1 advice for each severity.
-func (adv *Advisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {
+func (*Advisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {
return []advisor.Advice{
{
Status: advisor.Success,
diff --git a/plugin/advisor/utils_for_tests.go b/plugin/advisor/utils_for_tests.go
index c5e0393beb..aa84200095 100644
--- a/plugin/advisor/utils_for_tests.go
+++ b/plugin/advisor/utils_for_tests.go
@@ -30,7 +30,7 @@ var (
)
// FindIndex implements the catalog interface.
-func (c *MockCatalogService) FindIndex(ctx context.Context, find *catalog.IndexFind) (*catalog.Index, error) {
+func (*MockCatalogService) FindIndex(ctx context.Context, find *catalog.IndexFind) (*catalog.Index, error) {
switch find.IndexName {
case MockOldIndexName:
return &catalog.Index{
@@ -54,7 +54,7 @@ func (c *MockCatalogService) FindIndex(ctx context.Context, find *catalog.IndexF
}
// FindTable implements the catalog interface.
-func (c *MockCatalogService) FindTable(ctx context.Context, find *catalog.TableFind) ([]*catalog.Table, error) {
+func (*MockCatalogService) FindTable(ctx context.Context, find *catalog.TableFind) ([]*catalog.Table, error) {
return []*catalog.Table{
{
Name: "table",
diff --git a/plugin/db/clickhouse/clickhouse.go b/plugin/db/clickhouse/clickhouse.go
index b68e12893a..f84abcbbd2 100644
--- a/plugin/db/clickhouse/clickhouse.go
+++ b/plugin/db/clickhouse/clickhouse.go
@@ -38,12 +38,12 @@ type Driver struct {
db *sql.DB
}
-func newDriver(config db.DriverConfig) db.Driver {
+func newDriver(db.DriverConfig) db.Driver {
return &Driver{}
}
// Open opens a ClickHouse driver.
-func (driver *Driver) Open(ctx context.Context, dbType db.Type, config db.ConnectionConfig, connCtx db.ConnectionContext) (db.Driver, error) {
+func (driver *Driver) Open(_ context.Context, dbType db.Type, config db.ConnectionConfig, connCtx db.ConnectionContext) (db.Driver, error) {
port := config.Port
if port == "" {
port = "9000"
@@ -85,7 +85,7 @@ func (driver *Driver) Open(ctx context.Context, dbType db.Type, config db.Connec
}
// Close closes the driver.
-func (driver *Driver) Close(ctx context.Context) error {
+func (driver *Driver) Close(context.Context) error {
return driver.db.Close()
}
diff --git a/plugin/db/clickhouse/dump.go b/plugin/db/clickhouse/dump.go
index 37ef517cf7..77f98449eb 100644
--- a/plugin/db/clickhouse/dump.go
+++ b/plugin/db/clickhouse/dump.go
@@ -51,9 +51,9 @@ func (driver *Driver) Dump(ctx context.Context, database string, out io.Writer,
}
// getDatabases gets all databases of an instance.
-func getDatabases(txn *sql.Tx) ([]string, error) {
+func getDatabases(ctx context.Context, txn *sql.Tx) ([]string, error) {
var dbNames []string
- rows, err := txn.Query("SELECT name FROM system.databases")
+ rows, err := txn.QueryContext(ctx, "SELECT name FROM system.databases")
if err != nil {
return nil, err
}
@@ -75,7 +75,7 @@ func getDatabases(txn *sql.Tx) ([]string, error) {
// dumpTxn will dump the input database. schemaOnly isn't supported yet and true by default.
func dumpTxn(ctx context.Context, txn *sql.Tx, database string, out io.Writer, schemaOnly bool) error {
// Find all dumpable databases
- dbNames, err := getDatabases(txn)
+ dbNames, err := getDatabases(ctx, txn)
if err != nil {
return fmt.Errorf("failed to get databases: %s", err)
}
@@ -110,7 +110,7 @@ func dumpTxn(ctx context.Context, txn *sql.Tx, database string, out io.Writer, s
if _, err := io.WriteString(out, header); err != nil {
return err
}
- dbStmt, err := getDatabaseStmt(txn, dbName)
+ dbStmt, err := getDatabaseStmt(ctx, txn, dbName)
if err != nil {
return fmt.Errorf("failed to get database %q: %s", dbName, err)
}
@@ -125,7 +125,7 @@ func dumpTxn(ctx context.Context, txn *sql.Tx, database string, out io.Writer, s
}
// Table and view statement.
- tables, err := getTables(txn, dbName)
+ tables, err := getTables(ctx, txn, dbName)
if err != nil {
return fmt.Errorf("failed to get tables of database %q: %s", dbName, err)
}
@@ -140,10 +140,10 @@ func dumpTxn(ctx context.Context, txn *sql.Tx, database string, out io.Writer, s
}
// getDatabaseStmt gets the create statement of a database.
-func getDatabaseStmt(txn *sql.Tx, dbName string) (string, error) {
+func getDatabaseStmt(ctx context.Context, txn *sql.Tx, dbName string) (string, error) {
query := fmt.Sprintf("SHOW CREATE DATABASE IF NOT EXISTS %s;", dbName)
var stmt, unused string
- if err := txn.QueryRow(query).Scan(&unused, &stmt); err != nil {
+ if err := txn.QueryRowContext(ctx, query).Scan(&unused, &stmt); err != nil {
if err == sql.ErrNoRows {
return "", common.FormatDBErrorEmptyRowWithQuery(query)
}
@@ -160,10 +160,10 @@ type tableSchema struct {
}
// getTables gets all tables of a database.
-func getTables(txn *sql.Tx, dbName string) ([]*tableSchema, error) {
+func getTables(ctx context.Context, txn *sql.Tx, dbName string) ([]*tableSchema, error) {
var tables []*tableSchema
query := fmt.Sprintf("SELECT name, engine, create_table_query FROM system.tables WHERE database='%s';", dbName)
- rows, err := txn.Query(query)
+ rows, err := txn.QueryContext(ctx, query)
if err != nil {
return nil, err
}
@@ -211,11 +211,7 @@ func (driver *Driver) Restore(ctx context.Context, sc *bufio.Scanner) (err error
return err
}
- if err := txn.Commit(); err != nil {
- return err
- }
-
- return nil
+ return txn.Commit()
}
// RestoreTx restores the database in the given transaction.
diff --git a/plugin/db/clickhouse/migrate.go b/plugin/db/clickhouse/migrate.go
index 338441922f..c7f1a27c1b 100644
--- a/plugin/db/clickhouse/migrate.go
+++ b/plugin/db/clickhouse/migrate.go
@@ -269,7 +269,7 @@ func (driver *Driver) FindMigrationHistoryList(ctx context.Context, find *db.Mig
query += fmt.Sprintf(" LIMIT %d", *v)
}
// TODO(zp): modified param database of `util.FindMigrationHistoryList` when we support *clickhouse* database level.
- history, err := util.FindMigrationHistoryList(ctx, query, params, driver, db.BytebaseDatabase, find, baseQuery)
+ history, err := util.FindMigrationHistoryList(ctx, query, params, driver, db.BytebaseDatabase, baseQuery)
// TODO(d): remove this block once all existing customers all migrated to semantic versioning.
if err != nil {
if !strings.Contains(err.Error(), "invalid stored version") {
@@ -278,7 +278,7 @@ func (driver *Driver) FindMigrationHistoryList(ctx context.Context, find *db.Mig
if err := driver.updateMigrationHistoryStorageVersion(ctx); err != nil {
return nil, err
}
- return util.FindMigrationHistoryList(ctx, query, params, driver, db.BytebaseDatabase, find, baseQuery)
+ return util.FindMigrationHistoryList(ctx, query, params, driver, db.BytebaseDatabase, baseQuery)
}
return history, err
}
diff --git a/plugin/db/clickhouse/sync.go b/plugin/db/clickhouse/sync.go
index 833c2f41db..ca1103fec0 100644
--- a/plugin/db/clickhouse/sync.go
+++ b/plugin/db/clickhouse/sync.go
@@ -69,7 +69,6 @@ func (driver *Driver) SyncInstance(ctx context.Context) (*db.InstanceMeta, error
// SyncDBSchema syncs a single database schema.
func (driver *Driver) SyncDBSchema(ctx context.Context, databaseName string) (*db.Schema, error) {
-
// Query column info
columnWhere := fmt.Sprintf("LOWER(database) = '%s'", strings.ToLower(databaseName))
columnQuery := `
diff --git a/plugin/db/driver.go b/plugin/db/driver.go
index de2800f5b0..ba9c939492 100644
--- a/plugin/db/driver.go
+++ b/plugin/db/driver.go
@@ -14,6 +14,7 @@ import (
)
// Type is the type of a database.
+// nolint
type Type string
const (
diff --git a/plugin/db/mysql/dump.go b/plugin/db/mysql/dump.go
index 5177521b47..45cd47f186 100644
--- a/plugin/db/mysql/dump.go
+++ b/plugin/db/mysql/dump.go
@@ -418,7 +418,6 @@ func getTableStmt(txn *sql.Tx, dbName, tblName, tblType string) (string, error)
default:
return "", fmt.Errorf("unrecognized table type %q for database %q table %q", tblType, dbName, tblName)
}
-
}
// exportTableData gets the data of a table.
@@ -543,7 +542,6 @@ func getRoutineStmt(txn *sql.Tx, dbName, routineName, routineType string) (strin
return "", err
}
return fmt.Sprintf(routineStmtFmt, getReadableRoutineType(routineType), routineName, charset, charset, collation, sqlmode, stmt), nil
-
}
// getReadableRoutineType gets the printable routine type.
diff --git a/plugin/db/mysql/migrate.go b/plugin/db/mysql/migrate.go
index a610a10bcd..e8919a5a2d 100644
--- a/plugin/db/mysql/migrate.go
+++ b/plugin/db/mysql/migrate.go
@@ -251,7 +251,7 @@ func (driver *Driver) FindMigrationHistoryList(ctx context.Context, find *db.Mig
query += fmt.Sprintf(" LIMIT %d", *v)
}
// TODO(zp): modified param database of `util.FindMigrationHistoryList` when we support *mysql* database level.
- history, err := util.FindMigrationHistoryList(ctx, query, params, driver, db.BytebaseDatabase, find, baseQuery)
+ history, err := util.FindMigrationHistoryList(ctx, query, params, driver, db.BytebaseDatabase, baseQuery)
// TODO(d): remove this block once all existing customers all migrated to semantic versioning.
if err != nil {
if !strings.Contains(err.Error(), "invalid stored version") {
@@ -260,7 +260,7 @@ func (driver *Driver) FindMigrationHistoryList(ctx context.Context, find *db.Mig
if err := driver.updateMigrationHistoryStorageVersion(ctx); err != nil {
return nil, err
}
- return util.FindMigrationHistoryList(ctx, query, params, driver, db.BytebaseDatabase, find, baseQuery)
+ return util.FindMigrationHistoryList(ctx, query, params, driver, db.BytebaseDatabase, baseQuery)
}
return history, err
}
diff --git a/plugin/db/mysql/mysql.go b/plugin/db/mysql/mysql.go
index fe4a86db3f..c3da0d8ead 100644
--- a/plugin/db/mysql/mysql.go
+++ b/plugin/db/mysql/mysql.go
@@ -37,7 +37,7 @@ type Driver struct {
db *sql.DB
}
-func newDriver(config db.DriverConfig) db.Driver {
+func newDriver(db.DriverConfig) db.Driver {
return &Driver{}
}
diff --git a/plugin/db/pg/migrate.go b/plugin/db/pg/migrate.go
index 03ca45010b..4a2a848400 100644
--- a/plugin/db/pg/migrate.go
+++ b/plugin/db/pg/migrate.go
@@ -301,7 +301,7 @@ func (driver *Driver) FindMigrationHistoryList(ctx context.Context, find *db.Mig
if driver.strictUseDb() {
database = driver.strictDatabase
}
- history, err := util.FindMigrationHistoryList(ctx, query, params, driver, database, find, baseQuery)
+ history, err := util.FindMigrationHistoryList(ctx, query, params, driver, database, baseQuery)
// TODO(d): remove this block once all existing customers all migrated to semantic versioning.
// Skip this backfill for bytebase's database "bb" with user "bb". We will use the one in pg_engine.go instead.
isBytebaseDatabase := strings.Contains(driver.baseDSN, "user=bb") && strings.Contains(driver.baseDSN, "host=/tmp")
@@ -312,7 +312,7 @@ func (driver *Driver) FindMigrationHistoryList(ctx context.Context, find *db.Mig
if err := driver.updateMigrationHistoryStorageVersion(ctx); err != nil {
return nil, err
}
- return util.FindMigrationHistoryList(ctx, query, params, driver, db.BytebaseDatabase, find, baseQuery)
+ return util.FindMigrationHistoryList(ctx, query, params, driver, db.BytebaseDatabase, baseQuery)
}
return history, err
}
diff --git a/plugin/db/snowflake/migrate.go b/plugin/db/snowflake/migrate.go
index 1595a8a879..66c6030f08 100644
--- a/plugin/db/snowflake/migrate.go
+++ b/plugin/db/snowflake/migrate.go
@@ -279,7 +279,7 @@ func (driver *Driver) FindMigrationHistoryList(ctx context.Context, find *db.Mig
query += fmt.Sprintf(" LIMIT %d", *v)
}
// TODO(zp): modified param `bytebaseDatabase` of `util.FindMigrationHistoryList` when we support *snowflake* database level.
- history, err := util.FindMigrationHistoryList(ctx, query, params, driver, bytebaseDatabase, find, baseQuery)
+ history, err := util.FindMigrationHistoryList(ctx, query, params, driver, bytebaseDatabase, baseQuery)
// TODO(d): remove this block once all existing customers all migrated to semantic versioning.
if err != nil {
if !strings.Contains(err.Error(), "invalid stored version") {
@@ -288,7 +288,7 @@ func (driver *Driver) FindMigrationHistoryList(ctx context.Context, find *db.Mig
if err := driver.updateMigrationHistoryStorageVersion(ctx); err != nil {
return nil, err
}
- return util.FindMigrationHistoryList(ctx, query, params, driver, bytebaseDatabase, find, baseQuery)
+ return util.FindMigrationHistoryList(ctx, query, params, driver, bytebaseDatabase, baseQuery)
}
return history, err
}
diff --git a/plugin/db/sqlite/dump.go b/plugin/db/sqlite/dump.go
index 1a3de11fcc..b50b5b6db4 100644
--- a/plugin/db/sqlite/dump.go
+++ b/plugin/db/sqlite/dump.go
@@ -98,11 +98,7 @@ func (driver *Driver) dumpOneDatabase(ctx context.Context, database string, out
}
}
- if err := txn.Commit(); err != nil {
- return err
- }
-
- return nil
+ return txn.Commit()
}
// exportTableData gets the data of a table.
@@ -180,6 +176,6 @@ func (driver *Driver) Restore(ctx context.Context, sc *bufio.Scanner) (err error
}
// RestoreTx restores the database in the given transaction.
-func (driver *Driver) RestoreTx(ctx context.Context, tx *sql.Tx, sc *bufio.Scanner) error {
+func (*Driver) RestoreTx(ctx context.Context, tx *sql.Tx, sc *bufio.Scanner) error {
return fmt.Errorf("Unimplemented")
}
diff --git a/plugin/db/sqlite/migrate.go b/plugin/db/sqlite/migrate.go
index ff01126c17..7343f5ceee 100644
--- a/plugin/db/sqlite/migrate.go
+++ b/plugin/db/sqlite/migrate.go
@@ -268,5 +268,5 @@ func (driver *Driver) FindMigrationHistoryList(ctx context.Context, find *db.Mig
if v := find.Limit; v != nil {
query += fmt.Sprintf(" LIMIT %d", *v)
}
- return util.FindMigrationHistoryList(ctx, query, params, driver, bytebaseDatabase, find, baseQuery)
+ return util.FindMigrationHistoryList(ctx, query, params, driver, bytebaseDatabase, baseQuery)
}
diff --git a/plugin/db/util/driverutil.go b/plugin/db/util/driverutil.go
index df8b89efa6..0b71fa76d6 100644
--- a/plugin/db/util/driverutil.go
+++ b/plugin/db/util/driverutil.go
@@ -401,7 +401,7 @@ func Query(ctx context.Context, sqldb *sql.DB, statement string, limit int) ([]i
}
// FindMigrationHistoryList will find the list of migration history.
-func FindMigrationHistoryList(ctx context.Context, findMigrationHistoryListQuery string, queryParams []interface{}, driver db.Driver, database string, find *db.MigrationHistoryFind, baseQuery string) ([]*db.MigrationHistory, error) {
+func FindMigrationHistoryList(ctx context.Context, findMigrationHistoryListQuery string, queryParams []interface{}, driver db.Driver, database string, baseQuery string) ([]*db.MigrationHistory, error) {
// To support `pg` option, the util layer will not know which database where `migration_history` table is,
// so we need to connect to the database provided by params.
sqldb, err := driver.GetDBConnection(ctx, database)
diff --git a/plugin/vcs/gitlab/gitlab.go b/plugin/vcs/gitlab/gitlab.go
index 20f2a0c146..bcf8cc67f3 100644
--- a/plugin/vcs/gitlab/gitlab.go
+++ b/plugin/vcs/gitlab/gitlab.go
@@ -184,7 +184,7 @@ func newProvider(config vcs.ProviderConfig) vcs.Provider {
}
// APIURL returns the API URL path of a GitLab instance.
-func (p *Provider) APIURL(instanceURL string) string {
+func (*Provider) APIURL(instanceURL string) string {
return fmt.Sprintf("%s/%s", instanceURL, apiPath)
}
diff --git a/plugin/vcs/vcs.go b/plugin/vcs/vcs.go
index 025aaedae0..3ac07ab9c5 100644
--- a/plugin/vcs/vcs.go
+++ b/plugin/vcs/vcs.go
@@ -9,6 +9,7 @@ import (
)
// Type is the type of a VCS.
+// nolint
type Type string
const (
diff --git a/plugin/webhook/custom.go b/plugin/webhook/custom.go
index 426c02e946..3ffdd73aa1 100644
--- a/plugin/webhook/custom.go
+++ b/plugin/webhook/custom.go
@@ -36,7 +36,7 @@ func init() {
type CustomReceiver struct {
}
-func (receiver *CustomReceiver) post(context Context) error {
+func (*CustomReceiver) post(context Context) error {
payload := CustomWebhookRequest{
Level: context.Level,
ActivityType: context.ActivityType,
diff --git a/plugin/webhook/dingtalk.go b/plugin/webhook/dingtalk.go
index fa3a008329..32fda9fb89 100644
--- a/plugin/webhook/dingtalk.go
+++ b/plugin/webhook/dingtalk.go
@@ -36,7 +36,7 @@ func init() {
type DingTalkReceiver struct {
}
-func (receiver *DingTalkReceiver) post(context Context) error {
+func (*DingTalkReceiver) post(context Context) error {
metaStrList := []string{}
for _, meta := range context.getMetaList() {
metaStrList = append(metaStrList, fmt.Sprintf("##### **%s:** %s", meta.Name, meta.Value))
diff --git a/plugin/webhook/discord.go b/plugin/webhook/discord.go
index f26c7222b2..164bc4186d 100644
--- a/plugin/webhook/discord.go
+++ b/plugin/webhook/discord.go
@@ -50,7 +50,7 @@ func init() {
type DiscordReceiver struct {
}
-func (receiver *DiscordReceiver) post(context Context) error {
+func (*DiscordReceiver) post(context Context) error {
embedList := []DiscordWebhookEmbed{}
fieldList := []DiscordWebhookEmbedField{}
diff --git a/plugin/webhook/feishu.go b/plugin/webhook/feishu.go
index b56c15053f..bcfb8de727 100644
--- a/plugin/webhook/feishu.go
+++ b/plugin/webhook/feishu.go
@@ -57,7 +57,7 @@ func init() {
type FeishuReceiver struct {
}
-func (receiver *FeishuReceiver) post(context Context) error {
+func (*FeishuReceiver) post(context Context) error {
contentList := [][]FeishuWebhookPostSection{}
if context.Description != "" {
sectionList := []FeishuWebhookPostSection{}
diff --git a/plugin/webhook/slack.go b/plugin/webhook/slack.go
index d78bf656e6..ac05e7146d 100644
--- a/plugin/webhook/slack.go
+++ b/plugin/webhook/slack.go
@@ -49,7 +49,7 @@ func init() {
type SlackReceiver struct {
}
-func (receiver *SlackReceiver) post(context Context) error {
+func (*SlackReceiver) post(context Context) error {
blockList := []SlackWebhookBlock{}
status := ""
diff --git a/plugin/webhook/teams.go b/plugin/webhook/teams.go
index 7d4be14e53..ae47593f08 100644
--- a/plugin/webhook/teams.go
+++ b/plugin/webhook/teams.go
@@ -57,7 +57,7 @@ func init() {
type TeamsReceiver struct {
}
-func (receiver *TeamsReceiver) post(context Context) error {
+func (*TeamsReceiver) post(context Context) error {
factList := []TeamsWebhookSectionFact{}
for _, meta := range context.getMetaList() {
factList = append(factList, TeamsWebhookSectionFact(meta))
diff --git a/plugin/webhook/wecom.go b/plugin/webhook/wecom.go
index e445112c4d..60a9d9cfc5 100644
--- a/plugin/webhook/wecom.go
+++ b/plugin/webhook/wecom.go
@@ -35,7 +35,7 @@ func init() {
type WeComReceiver struct {
}
-func (receiver *WeComReceiver) post(context Context) error {
+func (*WeComReceiver) post(context Context) error {
metaStrList := []string{}
for _, meta := range context.getMetaList() {
metaStrList = append(metaStrList, fmt.Sprintf("%s: <font color=\"comment\">%s</font>", meta.Name, meta.Value))
diff --git a/resources/mysql/mysql.go b/resources/mysql/mysql.go
index 93eef243c9..477b37196a 100644
--- a/resources/mysql/mysql.go
+++ b/resources/mysql/mysql.go
@@ -78,7 +78,7 @@ func (i *Instance) Start(port int, stdout, stderr io.Writer) (err error) {
}
// Stop stops the mysql instance, outputs to stdout and stderr.
-func (i *Instance) Stop(stdout, stderr io.Writer) error {
+func (i *Instance) Stop() error {
return i.proc.Kill()
}
@@ -123,7 +123,9 @@ user=%s
if err != nil {
return nil, err
}
- fmt.Fprintf(defaultCfgFile, configFmt, basedir, datadir, user)
+ if _, err := fmt.Fprintf(defaultCfgFile, configFmt, basedir, datadir, user); err != nil {
+ return nil, err
+ }
defaultCfgFile.Close()
args := []string{
@@ -160,7 +162,7 @@ func SetupTestInstance(t *testing.T, port int) (*Instance, func()) {
stopFn := func() {
t.Log("Stopping Mysql...")
- if err := i.Stop(os.Stdout, os.Stderr); err != nil {
+ if err := i.Stop(); err != nil {
t.Fatal(err)
}
}
diff --git a/resources/mysql/mysql_test.go b/resources/mysql/mysql_test.go
index 85380a78ae..64cebd9073 100644
--- a/resources/mysql/mysql_test.go
+++ b/resources/mysql/mysql_test.go
@@ -33,6 +33,6 @@ func TestStartMySQL(t *testing.T) {
err = db.Ping()
require.NoError(t, err)
- err = mysql.Stop(os.Stdout, os.Stderr)
+ err = mysql.Stop()
require.NoError(t, err)
}
diff --git a/resources/postgres/postgres.go b/resources/postgres/postgres.go
index 15e9c6fd17..d0edee9e16 100644
--- a/resources/postgres/postgres.go
+++ b/resources/postgres/postgres.go
@@ -87,11 +87,7 @@ func (i *Instance) Stop(stdout, stderr io.Writer) error {
}
}
- if err := p.Run(); err != nil {
- return err
- }
-
- return nil
+ return p.Run()
}
// Install returns the postgres binary depending on the OS.
diff --git a/resources/utils/extract.go b/resources/utils/extract.go
index f925322883..9b4e85ab6d 100644
--- a/resources/utils/extract.go
+++ b/resources/utils/extract.go
@@ -64,7 +64,6 @@ func extractTar(r io.Reader, targetDir string) error {
if err != nil {
return err
}
- defer outFile.Close()
var totalWritten int64
for totalWritten < header.Size {
@@ -77,6 +76,9 @@ func extractTar(r io.Reader, targetDir string) error {
}
totalWritten += written
}
+ if err := outFile.Close(); err != nil {
+ return err
+ }
case tar.TypeDir:
if err := os.MkdirAll(targetPath, os.FileMode(header.Mode)); err != nil {
return err
diff --git a/server/openapi_metric.go b/server/openapi_metric.go
index a7fe966190..90a98243eb 100644
--- a/server/openapi_metric.go
+++ b/server/openapi_metric.go
@@ -33,9 +33,9 @@ func openAPIMetricMiddleware(s *Server, next echo.HandlerFunc) echo.HandlerFunc
}
}()
- if err = next(c); err != nil {
+ if err := next(c); err != nil {
c.Error(err)
}
- return
+ return nil
}
}
diff --git a/server/sheet.go b/server/sheet.go
index f44f2ced0f..4be7fdaae0 100644
--- a/server/sheet.go
+++ b/server/sheet.go
@@ -209,6 +209,7 @@ func (s *Server) registerSheetRoutes(g *echo.Group) {
}
for _, database := range databaseList {
+ database := database // create a new var "database".
if database.Instance.Environment.Name == sheetInfo.EnvironmentName {
databaseID = &database.ID
break
diff --git a/server/webhook.go b/server/webhook.go
index 8cda512054..66ceaa0db5 100644
--- a/server/webhook.go
+++ b/server/webhook.go
@@ -303,7 +303,7 @@ func dedupMigrationFilesFromCommitList(commitList []gitlab.WebhookCommit) []dist
}
for _, added := range commit.AddedList {
- new := true
+ isNew := true
item := distinctFileItem{
createdTime: createdTime,
commit: commit,
@@ -312,7 +312,7 @@ func dedupMigrationFilesFromCommitList(commitList []gitlab.WebhookCommit) []dist
for i, file := range distinctFileList {
// For the migration file with the same name, keep the one from the latest commit
if added == file.fileName {
- new = false
+ isNew = false
if file.createdTime.Before(createdTime) {
distinctFileList[i] = item
}
@@ -320,7 +320,7 @@ func dedupMigrationFilesFromCommitList(commitList []gitlab.WebhookCommit) []dist
}
}
- if new {
+ if isNew {
distinctFileList = append(distinctFileList, item)
}
}
diff --git a/store/backup.go b/store/backup.go
index a6d90f82c5..4dc6dfd89a 100644
--- a/store/backup.go
+++ b/store/backup.go
@@ -90,7 +90,7 @@ type backupSettingRaw struct {
// toBackupSetting creates an instance of BackupSetting based on the backupSettingRaw.
// This is intended to be called when we need to compose an BackupSetting relationship.
-func (raw *backupSettingRaw) toBackupSetting(mode common.ReleaseMode) *api.BackupSetting {
+func (raw *backupSettingRaw) toBackupSetting() *api.BackupSetting {
return &api.BackupSetting{
ID: raw.ID,
@@ -259,7 +259,7 @@ func (s *Store) composeBackup(ctx context.Context, raw *backupRaw) (*api.Backup,
}
func (s *Store) composeBackupSetting(ctx context.Context, raw *backupSettingRaw) (*api.BackupSetting, error) {
- backupSetting := raw.toBackupSetting(s.db.mode)
+ backupSetting := raw.toBackupSetting()
creator, err := s.GetPrincipalByID(ctx, backupSetting.CreatorID)
if err != nil {
diff --git a/store/data_source.go b/store/data_source.go
index 4cbaeab964..9106da72b6 100644
--- a/store/data_source.go
+++ b/store/data_source.go
@@ -93,19 +93,19 @@ func (s *Store) GetDataSource(ctx context.Context, find *api.DataSourceFind) (*a
// FindDataSource finds a list of DataSource instances
func (s *Store) FindDataSource(ctx context.Context, find *api.DataSourceFind) ([]*api.DataSource, error) {
- DataSourceRawList, err := s.findDataSourceRaw(ctx, find)
+ dataSourceRawList, err := s.findDataSourceRaw(ctx, find)
if err != nil {
return nil, fmt.Errorf("failed to find DataSource list with DataSourceFind[%+v], error: %w", find, err)
}
- var DataSourceList []*api.DataSource
- for _, raw := range DataSourceRawList {
- DataSource, err := s.composeDataSource(ctx, raw)
+ var dataSourceList []*api.DataSource
+ for _, raw := range dataSourceRawList {
+ dataSource, err := s.composeDataSource(ctx, raw)
if err != nil {
return nil, fmt.Errorf("failed to compose DataSource role with dataSourceRaw[%+v], error: %w", raw, err)
}
- DataSourceList = append(DataSourceList, DataSource)
+ dataSourceList = append(dataSourceList, dataSource)
}
- return DataSourceList, nil
+ return dataSourceList, nil
}
// PatchDataSource patches an instance of DataSource
@@ -114,11 +114,11 @@ func (s *Store) PatchDataSource(ctx context.Context, patch *api.DataSourcePatch)
if err != nil {
return nil, fmt.Errorf("failed to patch DataSource with DataSourcePatch[%+v], error: %w", patch, err)
}
- DataSource, err := s.composeDataSource(ctx, dataSourceRaw)
+ dataSource, err := s.composeDataSource(ctx, dataSourceRaw)
if err != nil {
return nil, fmt.Errorf("failed to compose DataSource role with dataSourceRaw[%+v], error: %w", dataSourceRaw, err)
}
- return DataSource, nil
+ return dataSource, nil
}
//
diff --git a/store/environment.go b/store/environment.go
index da4fcd6587..13ed48b100 100644
--- a/store/environment.go
+++ b/store/environment.go
@@ -50,28 +50,28 @@ func (s *Store) CreateEnvironment(ctx context.Context, create *api.EnvironmentCr
if err != nil {
return nil, fmt.Errorf("failed to create Environment with EnvironmentCreate[%+v], error: %w", create, err)
}
- Environment, err := s.composeEnvironment(ctx, environmentRaw)
+ environment, err := s.composeEnvironment(ctx, environmentRaw)
if err != nil {
return nil, fmt.Errorf("failed to compose Environment with environmentRaw[%+v], error: %w", environmentRaw, err)
}
- return Environment, nil
+ return environment, nil
}
// FindEnvironment finds a list of Environment instances
func (s *Store) FindEnvironment(ctx context.Context, find *api.EnvironmentFind) ([]*api.Environment, error) {
- EnvironmentRawList, err := s.findEnvironmentRaw(ctx, find)
+ environmentRawList, err := s.findEnvironmentRaw(ctx, find)
if err != nil {
return nil, fmt.Errorf("failed to find Environment list with EnvironmentFind[%+v], error: %w", find, err)
}
- var EnvironmentList []*api.Environment
- for _, raw := range EnvironmentRawList {
- Environment, err := s.composeEnvironment(ctx, raw)
+ var environmentList []*api.Environment
+ for _, raw := range environmentRawList {
+ environment, err := s.composeEnvironment(ctx, raw)
if err != nil {
return nil, fmt.Errorf("failed to compose Environment role with environmentRaw[%+v], error: %w", raw, err)
}
- EnvironmentList = append(EnvironmentList, Environment)
+ environmentList = append(environmentList, environment)
}
- return EnvironmentList, nil
+ return environmentList, nil
}
// PatchEnvironment patches an instance of Environment
@@ -80,11 +80,11 @@ func (s *Store) PatchEnvironment(ctx context.Context, patch *api.EnvironmentPatc
if err != nil {
return nil, fmt.Errorf("failed to patch Environment with EnvironmentPatch[%+v], error: %w", patch, err)
}
- Environment, err := s.composeEnvironment(ctx, environmentRaw)
+ environment, err := s.composeEnvironment(ctx, environmentRaw)
if err != nil {
return nil, fmt.Errorf("failed to compose Environment role with environmentRaw[%+v], error: %w", environmentRaw, err)
}
- return Environment, nil
+ return environment, nil
}
// GetEnvironmentByID gets an instance of Environment by ID
diff --git a/store/pipeline.go b/store/pipeline.go
index 6efefd8fea..f6ee205753 100644
--- a/store/pipeline.go
+++ b/store/pipeline.go
@@ -196,7 +196,7 @@ func (s *Store) findPipelineRaw(ctx context.Context, find *api.PipelineFind) ([]
}
defer tx.PTx.Rollback()
- list, err := s.findPipelineImpl(ctx, tx.PTx, find)
+ list, err := findPipelineImpl(ctx, tx.PTx, find)
if err != nil {
return nil, err
}
@@ -232,7 +232,7 @@ func (s *Store) getPipelineRaw(ctx context.Context, find *api.PipelineFind) (*pi
}
defer tx.PTx.Rollback()
- pipelineRawList, err := s.findPipelineImpl(ctx, tx.PTx, find)
+ pipelineRawList, err := findPipelineImpl(ctx, tx.PTx, find)
if err != nil {
return nil, err
}
@@ -307,7 +307,7 @@ func (s *Store) createPipelineImpl(ctx context.Context, tx *sql.Tx, create *api.
return &pipelineRaw, nil
}
-func (s *Store) findPipelineImpl(ctx context.Context, tx *sql.Tx, find *api.PipelineFind) ([]*pipelineRaw, error) {
+func findPipelineImpl(ctx context.Context, tx *sql.Tx, find *api.PipelineFind) ([]*pipelineRaw, error) {
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
if v := find.ID; v != nil {
diff --git a/store/repository.go b/store/repository.go
index 280e54dc31..4bb6585cae 100644
--- a/store/repository.go
+++ b/store/repository.go
@@ -221,7 +221,7 @@ func (s *Store) findRepositoryRaw(ctx context.Context, find *api.RepositoryFind)
}
defer tx.PTx.Rollback()
- list, err := findRepositoryImpl(ctx, tx.PTx, find, s.db.mode)
+ list, err := findRepositoryImpl(ctx, tx.PTx, find)
if err != nil {
return nil, err
}
@@ -238,7 +238,7 @@ func (s *Store) getRepositoryRaw(ctx context.Context, find *api.RepositoryFind)
}
defer tx.PTx.Rollback()
- list, err := findRepositoryImpl(ctx, tx.PTx, find, s.db.mode)
+ list, err := findRepositoryImpl(ctx, tx.PTx, find)
if err != nil {
return nil, err
}
@@ -260,7 +260,7 @@ func (s *Store) patchRepositoryRaw(ctx context.Context, patch *api.RepositoryPat
}
defer tx.PTx.Rollback()
- repository, err := patchRepositoryImpl(ctx, tx.PTx, patch, s.db.mode)
+ repository, err := patchRepositoryImpl(ctx, tx.PTx, patch)
if err != nil {
return nil, FormatError(err)
}
@@ -444,7 +444,7 @@ func (s *Store) createRepositoryImpl(ctx context.Context, tx *sql.Tx, create *ap
return &repository, nil
}
-func findRepositoryImpl(ctx context.Context, tx *sql.Tx, find *api.RepositoryFind, mode common.ReleaseMode) ([]*repositoryRaw, error) {
+func findRepositoryImpl(ctx context.Context, tx *sql.Tx, find *api.RepositoryFind) ([]*repositoryRaw, error) {
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
if v := find.ID; v != nil {
@@ -536,7 +536,7 @@ func findRepositoryImpl(ctx context.Context, tx *sql.Tx, find *api.RepositoryFin
}
// patchRepositoryImpl updates a repository by ID. Returns the new state of the repository after update.
-func patchRepositoryImpl(ctx context.Context, tx *sql.Tx, patch *api.RepositoryPatch, mode common.ReleaseMode) (*repositoryRaw, error) {
+func patchRepositoryImpl(ctx context.Context, tx *sql.Tx, patch *api.RepositoryPatch) (*repositoryRaw, error) {
// Build UPDATE clause.
set, args := []string{"updater_id = $1"}, []interface{}{patch.UpdaterID}
if v := patch.BranchFilter; v != nil {
diff --git a/store/task.go b/store/task.go
index c38f50d174..44ccce4666 100644
--- a/store/task.go
+++ b/store/task.go
@@ -127,7 +127,6 @@ func (s *Store) FindTask(ctx context.Context, find *api.TaskFind, returnOnErr bo
zap.Any("taskRaw", raw),
zap.Error(err))
continue
-
}
taskList = append(taskList, task)
}
diff --git a/tests/backup_restore_test.go b/tests/backup_restore_test.go
index 2c91a57503..eed52434ab 100644
--- a/tests/backup_restore_test.go
+++ b/tests/backup_restore_test.go
@@ -18,7 +18,6 @@ import (
"github.com/bytebase/bytebase/api"
"github.com/bytebase/bytebase/common/log"
"github.com/bytebase/bytebase/plugin/db"
- dbplugin "github.com/bytebase/bytebase/plugin/db"
resourcemysql "github.com/bytebase/bytebase/resources/mysql"
"go.uber.org/zap/zapcore"
@@ -116,8 +115,8 @@ func TestPITR(t *testing.T) {
ctx := context.Background()
port := getTestPort(t.Name())
ctl := &controller{}
- datadir := t.TempDir()
- err := ctl.StartServer(ctx, datadir, port)
+ dataDir := t.TempDir()
+ err := ctl.StartServer(ctx, dataDir, port)
a.NoError(err)
defer ctl.Close(ctx)
err = ctl.Login()
@@ -852,7 +851,7 @@ func validateTableUpdateRow(t *testing.T, db *sql.DB, databaseName string) {
a.NoError(rows.Err())
}
-func doBackup(ctx context.Context, driver dbplugin.Driver, database string) (*bytes.Buffer, *api.BackupPayload, error) {
+func doBackup(ctx context.Context, driver db.Driver, database string) (*bytes.Buffer, *api.BackupPayload, error) {
var buf bytes.Buffer
var backupPayload api.BackupPayload
backupPayloadString, err := driver.Dump(ctx, database, &buf, false)
diff --git a/tests/mysql_prepare.go b/tests/mysql_prepare.go
index 57114a48fe..c97dab6e2e 100644
--- a/tests/mysql_prepare.go
+++ b/tests/mysql_prepare.go
@@ -9,12 +9,11 @@ import (
"fmt"
"math/rand"
- _ "github.com/go-sql-driver/mysql"
"github.com/google/uuid"
)
func prepare(port int, tableSize int) error {
- const createTableSql = `CREATE TABLE sbtest1 (
+ const createTableSQL = `CREATE TABLE sbtest1 (
id INT NOT NULL,
k INT NOT NULL DEFAULT 0,
c CHAR(120) NOT NULL DEFAULT '',
@@ -32,7 +31,7 @@ KEY k_1 (k)
if err != nil {
return err
}
- _, err = db.Exec(createTableSql)
+ _, err = db.Exec(createTableSQL)
if err != nil {
return err
}
@@ -46,12 +45,12 @@ KEY k_1 (k)
}
func insert(db *sql.DB, insertCount int, batchCount int) error {
- const insertSql = `INSERT INTO sbtest1 (id, k, c, pad) VALUES `
+ const insertSQL = `INSERT INTO sbtest1 (id, k, c, pad) VALUES `
var buf bytes.Buffer
for i := 0; i < insertCount; i += batchCount {
buf.Reset()
// We use bytes.Buffer here to concat the strings because strings are too slow.
- buf.WriteString(insertSql)
+ buf.WriteString(insertSQL)
for j := 0; j < batchCount; j++ {
id := i + j
if id >= insertCount {
diff --git a/tests/tests.go b/tests/tests.go
index f566340012..6db2277d93 100644
--- a/tests/tests.go
+++ b/tests/tests.go
@@ -839,7 +839,6 @@ func getNextTaskStatus(issue *api.Issue) (api.TaskStatus, error) {
}
// waitIssueNextTaskWithTaskApproval waits for next task in pipeline to finish and approves it when necessary.
-// nolint
func (ctl *controller) waitIssueNextTaskWithTaskApproval(id int) (api.TaskStatus, error) {
return ctl.waitIssuePipelineTaskImpl(id, ctl.approveIssueNext, true)
}