Skip to content

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

fix: resolve golangci-lint v2.10.1 issues across codebase (#19475)

h3n4l2b62cb2887f0
diff --git a/action/github/github.go b/action/github/github.go
index 839c083cf1..0e5c8999ca 100644
--- a/action/github/github.go
+++ b/action/github/github.go
@@ -119,9 +119,9 @@ func buildCommentMessage(resp *v1pb.CheckReleaseResponse) string {
var sb strings.Builder
_, _ = sb.WriteString(commentHeader + "\n")
_, _ = sb.WriteString("## SQL Review Summary\n\n")
- _, _ = sb.WriteString(fmt.Sprintf("* Total Affected Rows: **%d**\n", resp.AffectedRows))
- _, _ = sb.WriteString(fmt.Sprintf("* Overall Risk Level: **%s**\n", formatRiskLevel(resp.RiskLevel)))
- _, _ = sb.WriteString(fmt.Sprintf("* Advices Statistics: **%d Error(s), %d Warning(s)**\n", errorCount, warningCount))
+ _, _ = fmt.Fprintf(&sb, "* Total Affected Rows: **%d**\n", resp.AffectedRows)
+ _, _ = fmt.Fprintf(&sb, "* Overall Risk Level: **%s**\n", formatRiskLevel(resp.RiskLevel))
+ _, _ = fmt.Fprintf(&sb, "* Advices Statistics: **%d Error(s), %d Warning(s)**\n", errorCount, warningCount)
_, _ = sb.WriteString("### Detailed Results\n")
_, _ = sb.WriteString(`
<table>
@@ -164,13 +164,13 @@ func buildCommentMessage(resp *v1pb.CheckReleaseResponse) string {
adviceCell = strings.Join(counts, ", ")
}
- _, _ = sb.WriteString(fmt.Sprintf(`<tr>
+ _, _ = fmt.Fprintf(&sb, `<tr>
<td>%s</td>
<td>%s</td>
<td>%d</td>
<td>%s</td>
<td>%s</td>
-</tr>`, result.File, result.Target, result.AffectedRows, formatRiskLevel(result.RiskLevel), adviceCell))
+</tr>`, result.File, result.Target, result.AffectedRows, formatRiskLevel(result.RiskLevel), adviceCell)
}
_, _ = sb.WriteString("</tbody></table>")
return sb.String()
diff --git a/backend/api/mcp/tool_call.go b/backend/api/mcp/tool_call.go
index 90bce6f37e..d2b0451ab7 100644
--- a/backend/api/mcp/tool_call.go
+++ b/backend/api/mcp/tool_call.go
@@ -150,12 +150,12 @@ func (s *Server) handleCallAPI(ctx context.Context, _ *mcp.CallToolRequest, inpu
func formatCallOutput(output CallOutput, endpoint *EndpointInfo) string {
var sb strings.Builder
- sb.WriteString(fmt.Sprintf("## %s\n\n", endpoint.OperationID))
+ fmt.Fprintf(&sb, "## %s\n\n", endpoint.OperationID)
if output.Error != "" {
- sb.WriteString(fmt.Sprintf("**Error** (HTTP %d): %s\n\n", output.Status, output.Error))
+ fmt.Fprintf(&sb, "**Error** (HTTP %d): %s\n\n", output.Status, output.Error)
} else {
- sb.WriteString(fmt.Sprintf("**Status:** %d OK\n\n", output.Status))
+ fmt.Fprintf(&sb, "**Status:** %d OK\n\n", output.Status)
}
if output.Response != nil {
diff --git a/backend/api/mcp/tool_search.go b/backend/api/mcp/tool_search.go
index b4a9152791..6091cad394 100644
--- a/backend/api/mcp/tool_search.go
+++ b/backend/api/mcp/tool_search.go
@@ -119,10 +119,10 @@ func (s *Server) formatServiceList() string {
for _, svc := range services {
endpoints := s.openAPIIndex.GetServiceEndpoints(svc)
- sb.WriteString(fmt.Sprintf("- **%s** (%d endpoints)\n", svc, len(endpoints)))
+ fmt.Fprintf(&sb, "- **%s** (%d endpoints)\n", svc, len(endpoints))
}
- sb.WriteString(fmt.Sprintf("\nTotal: %d services\n", len(services)))
+ fmt.Fprintf(&sb, "\nTotal: %d services\n", len(services))
return sb.String()
}
@@ -130,18 +130,18 @@ func (*Server) formatEndpoints(endpoints []*EndpointInfo, limit int) string {
var sb strings.Builder
if limit > 0 && len(endpoints) > limit {
- sb.WriteString(fmt.Sprintf("Showing %d of %d results:\n\n", limit, len(endpoints)))
+ fmt.Fprintf(&sb, "Showing %d of %d results:\n\n", limit, len(endpoints))
endpoints = endpoints[:limit]
} else {
- sb.WriteString(fmt.Sprintf("Found %d endpoints:\n\n", len(endpoints)))
+ fmt.Fprintf(&sb, "Found %d endpoints:\n\n", len(endpoints))
}
for i, ep := range endpoints {
- sb.WriteString(fmt.Sprintf("### %d. %s/%s\n", i+1, ep.Service, ep.Method))
- sb.WriteString(fmt.Sprintf("%s\n", ep.Summary))
+ fmt.Fprintf(&sb, "### %d. %s/%s\n", i+1, ep.Service, ep.Method)
+ fmt.Fprintf(&sb, "%s\n", ep.Summary)
if len(ep.Permissions) > 0 {
- sb.WriteString(fmt.Sprintf("Permissions: `%s`\n", strings.Join(ep.Permissions, "`, `")))
+ fmt.Fprintf(&sb, "Permissions: `%s`\n", strings.Join(ep.Permissions, "`, `"))
}
sb.WriteString("\n")
}
@@ -157,11 +157,11 @@ func (s *Server) formatEndpointDetail(operationID string) string {
var sb strings.Builder
- sb.WriteString(fmt.Sprintf("## %s/%s\n\n", ep.Service, ep.Method))
- sb.WriteString(fmt.Sprintf("%s\n\n", ep.Summary))
+ fmt.Fprintf(&sb, "## %s/%s\n\n", ep.Service, ep.Method)
+ fmt.Fprintf(&sb, "%s\n\n", ep.Summary)
if len(ep.Permissions) > 0 {
- sb.WriteString(fmt.Sprintf("**Permissions:** `%s`\n\n", strings.Join(ep.Permissions, "`, `")))
+ fmt.Fprintf(&sb, "**Permissions:** `%s`\n\n", strings.Join(ep.Permissions, "`, `"))
}
// Request schema
@@ -205,7 +205,7 @@ func (s *Server) formatSchemaDetail(schemaName string) string {
displayName = "bytebase.v1." + schemaName
}
- sb.WriteString(fmt.Sprintf("## %s\n\n", displayName))
+ fmt.Fprintf(&sb, "## %s\n\n", displayName)
// Check if it's an enum
if len(props) == 1 && props[0].Name == "enum" {
diff --git a/backend/api/mcp/tool_skill.go b/backend/api/mcp/tool_skill.go
index 4b241947c8..0190b71aa9 100644
--- a/backend/api/mcp/tool_skill.go
+++ b/backend/api/mcp/tool_skill.go
@@ -69,7 +69,7 @@ func (*Server) formatSkillList() string {
if !entry.IsDir() && strings.HasSuffix(entry.Name(), ".md") {
meta := parseSkillMeta(entry.Name())
if meta != nil {
- sb.WriteString(fmt.Sprintf("| %s | %s |\n", meta.Name, meta.Description))
+ fmt.Fprintf(&sb, "| %s | %s |\n", meta.Name, meta.Description)
}
}
}
diff --git a/backend/common/util.go b/backend/common/util.go
index f942a48860..02dacbd602 100644
--- a/backend/common/util.go
+++ b/backend/common/util.go
@@ -211,7 +211,7 @@ func SanitizeUTF8String(s string) string {
_, wid := utf8.DecodeRuneInString(s[i:])
if wid == 1 {
i++
- _, _ = b.WriteString(fmt.Sprintf("\\x%02x", c))
+ _, _ = fmt.Fprintf(&b, "\\x%02x", c)
continue
}
_, _ = b.WriteString(s[i : i+wid])
diff --git a/backend/component/masker/masker.go b/backend/component/masker/masker.go
index 575e0d0566..bacc6fd11b 100644
--- a/backend/component/masker/masker.go
+++ b/backend/component/masker/masker.go
@@ -715,6 +715,7 @@ func (m *InnerOuterMasker) Mask(data *MaskData) *v1pb.RowValue {
z := time.FixedZone(kind.TimestampTzValue.GetZone(), int(kind.TimestampTzValue.GetOffset()))
s := t.In(z).Format(time.RFC3339Nano)
unmaskedData = s
+ default:
}
if isDataNullOrBool {
return &v1pb.RowValue{
diff --git a/backend/plugin/advisor/template_test.go b/backend/plugin/advisor/template_test.go
index 081e264c06..1bf62dac92 100644
--- a/backend/plugin/advisor/template_test.go
+++ b/backend/plugin/advisor/template_test.go
@@ -43,9 +43,9 @@ func TestTemplateAdvisorRegistrations(t *testing.T) {
if len(mismatches) > 0 {
var errMsg strings.Builder
- errMsg.WriteString(fmt.Sprintf("\nFound %d advisor rule(s) in template that are NOT registered in Go code:\n", len(mismatches)))
+ fmt.Fprintf(&errMsg, "\nFound %d advisor rule(s) in template that are NOT registered in Go code:\n", len(mismatches))
for _, mismatch := range mismatches {
- errMsg.WriteString(fmt.Sprintf(" - Engine: %s, Rule: %s\n", mismatch.Engine, mismatch.RuleType))
+ fmt.Fprintf(&errMsg, " - Engine: %s, Rule: %s\n", mismatch.Engine, mismatch.RuleType)
}
errMsg.WriteString("\nTo fix this issue:\n")
errMsg.WriteString("1. Remove the invalid rule from the template file, OR\n")
diff --git a/backend/plugin/db/databricks/dump.go b/backend/plugin/db/databricks/dump.go
index f4ef7ed9ef..7f80b679c8 100644
--- a/backend/plugin/db/databricks/dump.go
+++ b/backend/plugin/db/databricks/dump.go
@@ -147,15 +147,15 @@ func genMaterializedViewDDL(qualifiedName string, mtViewMeta *storepb.Materializ
return "", err
}
- if _, err := builder.WriteString(fmt.Sprintf("CREATE MATERIALIZED VIEW %s\n", qualifiedName)); err != nil {
+ if _, err := fmt.Fprintf(&builder, "CREATE MATERIALIZED VIEW %s\n", qualifiedName); err != nil {
return "", err
}
- if _, err := builder.WriteString(fmt.Sprintf("COMMENT %s\n", mtViewMeta.Comment)); err != nil {
+ if _, err := fmt.Fprintf(&builder, "COMMENT %s\n", mtViewMeta.Comment); err != nil {
return "", err
}
- if _, err := builder.WriteString(fmt.Sprintf("TBLPROPERTIES %s\n", tblProperties)); err != nil {
+ if _, err := fmt.Fprintf(&builder, "TBLPROPERTIES %s\n", tblProperties); err != nil {
return "", err
}
@@ -205,7 +205,7 @@ func formatTblProperties(tblAddInfo *tableAdditionalInfo) (string, error) {
if idx == len(tblAddInfo.tblProps)-1 {
comma = ""
}
- if _, err := builder.WriteString(fmt.Sprintf("%s = %s%s\n", key, val, comma)); err != nil {
+ if _, err := fmt.Fprintf(&builder, "%s = %s%s\n", key, val, comma); err != nil {
return "", err
}
idx++
diff --git a/backend/plugin/db/hive/dump.go b/backend/plugin/db/hive/dump.go
index 916450fae9..d7386604ed 100644
--- a/backend/plugin/db/hive/dump.go
+++ b/backend/plugin/db/hive/dump.go
@@ -107,7 +107,7 @@ func (d *Driver) Dump(ctx context.Context, out io.Writer, _ *storepb.DatabaseSch
return errors.Wrapf(err, "failed to generate DDL for index %s", index.Name)
}
- _, _ = builder.WriteString(fmt.Sprintf(schemaStmtFmt, "INDEX", fmt.Sprintf("`%s`", index.Name), indexDDL))
+ _, _ = fmt.Fprintf(&builder, schemaStmtFmt, "INDEX", fmt.Sprintf("`%s`", index.Name), indexDDL)
}
_, _ = builder.WriteString(tableDDL)
}
@@ -153,7 +153,7 @@ func (d *Driver) Dump(ctx context.Context, out io.Writer, _ *storepb.DatabaseSch
return errors.Wrapf(err, "failed to generate DDL for materialized view %s", mtView.Name)
}
- _, _ = builder.WriteString(fmt.Sprintf(schemaStmtFmt, "MATERIALIZED VIEW", fmt.Sprintf("`%s`.`%s`", databaseName, mtView.Name), mtViewDDL))
+ _, _ = fmt.Fprintf(&builder, schemaStmtFmt, "MATERIALIZED VIEW", fmt.Sprintf("`%s`.`%s`", databaseName, mtView.Name), mtViewDDL)
}
if _, err = io.WriteString(out, builder.String()); err != nil {
@@ -202,13 +202,13 @@ func genIndexDDL(opts *IndexDDLOptions) (string, error) {
var builder strings.Builder
// index name, table name.
- _, _ = builder.WriteString(fmt.Sprintf("CREATE INDEX `%s`\nON TABLE %s ", opts.indexName, fmt.Sprintf("`%s`.`%s`", opts.databaseName, opts.tableName)))
+ _, _ = fmt.Fprintf(&builder, "CREATE INDEX `%s`\nON TABLE %s ", opts.indexName, fmt.Sprintf("`%s`.`%s`", opts.databaseName, opts.tableName))
// column names.
formatColumn(&builder, opts.colNames)
// index type.
- _, _ = builder.WriteString(fmt.Sprintf(")\nAS '%s'\n", opts.indexType))
+ _, _ = fmt.Fprintf(&builder, ")\nAS '%s'\n", opts.indexType)
// with deferred rebuild.
if opts.isWithDeferredRebuild {
@@ -223,7 +223,7 @@ func genIndexDDL(opts *IndexDDLOptions) (string, error) {
// index table.
if opts.indexTableName != "" {
- _, _ = builder.WriteString(fmt.Sprintf("IN TABLE %s\n", opts.indexTableName))
+ _, _ = fmt.Fprintf(&builder, "IN TABLE %s\n", opts.indexTableName)
}
// row format.
@@ -237,10 +237,10 @@ func genIndexDDL(opts *IndexDDLOptions) (string, error) {
return "", errors.New("keywords 'STORED AS' and 'STORED BY' cannot appear at the same time")
}
if opts.storedAs != "" {
- _, _ = builder.WriteString(fmt.Sprintf("STORED AS %s\n", opts.storedAs))
+ _, _ = fmt.Fprintf(&builder, "STORED AS %s\n", opts.storedAs)
}
if opts.storedBy != "" {
- _, _ = builder.WriteString(fmt.Sprintf("STORED BY '%s'\n", opts.storedBy))
+ _, _ = fmt.Fprintf(&builder, "STORED BY '%s'\n", opts.storedBy)
}
// location.
@@ -257,7 +257,7 @@ func genIndexDDL(opts *IndexDDLOptions) (string, error) {
// comment.
if opts.comment != "" {
- _, _ = builder.WriteString(fmt.Sprintf("COMMENT '%s'\n", opts.comment))
+ _, _ = fmt.Fprintf(&builder, "COMMENT '%s'\n", opts.comment)
}
return builder.String(), nil
@@ -268,7 +268,7 @@ func genMaterializedViewDDL(opts *MaterializedViewDDLOptions) (string, error) {
viewNameWithDB := fmt.Sprintf("`%s`.`%s`", opts.databaseName, opts.mtViewName)
// mtView name.
- _, _ = builder.WriteString(fmt.Sprintf("CREATE MATERIALIZED VIEW %s\n", viewNameWithDB))
+ _, _ = fmt.Fprintf(&builder, "CREATE MATERIALIZED VIEW %s\n", viewNameWithDB)
// disable rewrite.
if opts.disableRewrite {
@@ -277,7 +277,7 @@ func genMaterializedViewDDL(opts *MaterializedViewDDLOptions) (string, error) {
// comment.
if opts.comment != "" {
- _, _ = builder.WriteString(fmt.Sprintf("COMMENT '%s'\n", opts.comment))
+ _, _ = fmt.Fprintf(&builder, "COMMENT '%s'\n", opts.comment)
}
// partitioned on.
@@ -310,10 +310,10 @@ func genMaterializedViewDDL(opts *MaterializedViewDDLOptions) (string, error) {
return "", errors.New("keywords 'STORED AS' and 'STORED BY' cannot appear at the same time")
}
if opts.storedAs != "" {
- _, _ = builder.WriteString(fmt.Sprintf("STORED AS %s\n", opts.storedAs))
+ _, _ = fmt.Fprintf(&builder, "STORED AS %s\n", opts.storedAs)
}
if opts.storedBy != "" {
- _, _ = builder.WriteString(fmt.Sprintf("STORED BY '%s'\n", opts.storedBy))
+ _, _ = fmt.Fprintf(&builder, "STORED BY '%s'\n", opts.storedBy)
// if with serde properties.
if opts.serdProperties != nil {
@@ -335,7 +335,7 @@ func genMaterializedViewDDL(opts *MaterializedViewDDLOptions) (string, error) {
}
// as.
- _, _ = builder.WriteString(fmt.Sprintf("AS %s \n", opts.as))
+ _, _ = fmt.Fprintf(&builder, "AS %s \n", opts.as)
return builder.String(), nil
}
diff --git a/backend/plugin/db/pg/sync.go b/backend/plugin/db/pg/sync.go
index ad95652342..5ac5ee749b 100644
--- a/backend/plugin/db/pg/sync.go
+++ b/backend/plugin/db/pg/sync.go
@@ -1511,7 +1511,7 @@ func getEventTriggers(txn *sql.Tx, extensionDepend map[int]bool) ([]*storepb.Eve
func buildEventTriggerDefinition(et *storepb.EventTriggerMetadata) string {
var buf strings.Builder
buf.WriteString("CREATE EVENT TRIGGER ")
- buf.WriteString(fmt.Sprintf("%q", et.Name))
+ fmt.Fprintf(&buf, "%q", et.Name)
buf.WriteString(" ON ")
buf.WriteString(et.Event)
@@ -1530,10 +1530,10 @@ func buildEventTriggerDefinition(et *storepb.EventTriggerMetadata) string {
buf.WriteString("\n EXECUTE FUNCTION ")
if et.FunctionSchema != "" {
- buf.WriteString(fmt.Sprintf("%q", et.FunctionSchema))
+ fmt.Fprintf(&buf, "%q", et.FunctionSchema)
buf.WriteString(".")
}
- buf.WriteString(fmt.Sprintf("%q", et.FunctionName))
+ fmt.Fprintf(&buf, "%q", et.FunctionName)
buf.WriteString("()")
return buf.String()
diff --git a/backend/plugin/parser/elasticsearch/masking.go b/backend/plugin/parser/elasticsearch/masking.go
index 70d5fef3ea..acb3626af1 100644
--- a/backend/plugin/parser/elasticsearch/masking.go
+++ b/backend/plugin/parser/elasticsearch/masking.go
@@ -284,6 +284,7 @@ func extractSource(parsed map[string]any, result *RequestAnalysis) {
result.SourceFields = toStringSlice(arr)
}
}
+ default:
}
}
@@ -350,6 +351,7 @@ func extractSortFields(parsed map[string]any) []string {
fields = append(fields, k)
}
}
+ default:
}
}
return fields
@@ -379,6 +381,7 @@ func containsKeyInValue(v any, key string) bool {
return true
}
}
+ default:
}
return false
}
@@ -488,6 +491,7 @@ func extractCompoundClauseFields(clauseObj map[string]any, subQueryKeys []string
extractFieldsFromQuery(sq, fields)
case []any:
extractFieldsFromQueryArray(sq, fields)
+ default:
}
}
}
diff --git a/backend/plugin/parser/mongodb/masking.go b/backend/plugin/parser/mongodb/masking.go
index 68cadcc392..ca5b40ca2e 100644
--- a/backend/plugin/parser/mongodb/masking.go
+++ b/backend/plugin/parser/mongodb/masking.go
@@ -166,6 +166,7 @@ func extractCollectionName(access mongoparser.ICollectionAccessContext) string {
if sl := access.StringLiteral(); sl != nil {
return unquoteMongoString(sl.GetText())
}
+ default:
}
return ""
}
@@ -323,6 +324,7 @@ func extractPairKey(keyCtx mongoparser.IKeyContext) string {
if sl := keyCtx.StringLiteral(); sl != nil {
return unquoteMongoString(sl.GetText())
}
+ default:
}
if keyCtx == nil {
return ""
diff --git a/backend/plugin/parser/mysql/backup.go b/backend/plugin/parser/mysql/backup.go
index 70e7e7ef6c..de9b1dde9c 100644
--- a/backend/plugin/parser/mysql/backup.go
+++ b/backend/plugin/parser/mysql/backup.go
@@ -167,11 +167,11 @@ func generateSQLForTable(ctx context.Context, tCtx base.TransformContext, statem
targetTable := fmt.Sprintf("%s_%s_%s", tablePrefix, table.Table, table.Database)
targetTable, _ = common.TruncateString(targetTable, maxTableNameLength)
var buf strings.Builder
- if _, err := buf.WriteString(fmt.Sprintf("CREATE TABLE `%s`.`%s` LIKE `%s`.`%s`;\n", databaseName, targetTable, table.Database, table.Table)); err != nil {
+ if _, err := fmt.Fprintf(&buf, "CREATE TABLE `%s`.`%s` LIKE `%s`.`%s`;\n", databaseName, targetTable, table.Database, table.Table); err != nil {
return nil, errors.Wrap(err, "failed to write create table statement")
}
- if _, err := buf.WriteString(fmt.Sprintf("INSERT INTO `%s`.`%s`", databaseName, targetTable)); err != nil {
+ if _, err := fmt.Fprintf(&buf, "INSERT INTO `%s`.`%s`", databaseName, targetTable); err != nil {
return nil, errors.Wrap(err, "failed to write insert into statement")
}
if len(generatedColumns) > 0 {
@@ -184,7 +184,7 @@ func generateSQLForTable(ctx context.Context, tCtx base.TransformContext, statem
return nil, errors.Wrap(err, "failed to write comma")
}
}
- if _, err := buf.WriteString(fmt.Sprintf("`%s`", column)); err != nil {
+ if _, err := fmt.Fprintf(&buf, "`%s`", column); err != nil {
return nil, errors.Wrap(err, "failed to write column")
}
}
@@ -209,12 +209,12 @@ func generateSQLForTable(ctx context.Context, tCtx base.TransformContext, statem
}
cteString := extractCTE(item.Tree)
if len(cteString) > 0 {
- if _, err := buf.WriteString(fmt.Sprintf("%s ", cteString)); err != nil {
+ if _, err := fmt.Fprintf(&buf, "%s ", cteString); err != nil {
return nil, errors.Wrap(err, "failed to write cte")
}
}
if len(generatedColumns) == 0 {
- if _, err := buf.WriteString(fmt.Sprintf("SELECT `%s`.* FROM ", tableNameOrAlias)); err != nil {
+ if _, err := fmt.Fprintf(&buf, "SELECT `%s`.* FROM ", tableNameOrAlias); err != nil {
return nil, errors.Wrap(err, "failed to write select statement")
}
} else {
@@ -227,7 +227,7 @@ func generateSQLForTable(ctx context.Context, tCtx base.TransformContext, statem
return nil, errors.Wrap(err, "failed to write comma")
}
}
- if _, err := buf.WriteString(fmt.Sprintf("`%s`.`%s`", tableNameOrAlias, column)); err != nil {
+ if _, err := fmt.Fprintf(&buf, "`%s`.`%s`", tableNameOrAlias, column); err != nil {
return nil, errors.Wrap(err, "failed to write column")
}
}
diff --git a/backend/plugin/parser/plsql/backup.go b/backend/plugin/parser/plsql/backup.go
index 93d7e65fdf..c88bd46bb3 100644
--- a/backend/plugin/parser/plsql/backup.go
+++ b/backend/plugin/parser/plsql/backup.go
@@ -135,7 +135,7 @@ func generateSQLForTable(ctx base.TransformContext, statementInfoList []statemen
}
var buf strings.Builder
- if _, err := buf.WriteString(fmt.Sprintf(`CREATE TABLE "%s"."%s" AS`+"\n", targetDatabase, targetTable)); err != nil {
+ if _, err := fmt.Fprintf(&buf, `CREATE TABLE "%s"."%s" AS`+"\n", targetDatabase, targetTable); err != nil {
return nil, errors.Wrap(err, "failed to write to buffer")
}
for i, info := range statementInfoList {
@@ -146,16 +146,16 @@ func generateSQLForTable(ctx base.TransformContext, statementInfoList []statemen
}
t := info.table
if t.Alias != "" {
- if _, err := buf.WriteString(fmt.Sprintf(` SELECT "%s".* FROM `, t.Alias)); err != nil {
+ if _, err := fmt.Fprintf(&buf, ` SELECT "%s".* FROM `, t.Alias); err != nil {
return nil, errors.Wrap(err, "failed to write to buffer")
}
} else {
if t.HasSchema {
- if _, err := buf.WriteString(fmt.Sprintf(` SELECT "%s"."%s".* FROM `, t.Schema, t.Table)); err != nil {
+ if _, err := fmt.Fprintf(&buf, ` SELECT "%s"."%s".* FROM `, t.Schema, t.Table); err != nil {
return nil, errors.Wrap(err, "failed to write to buffer")
}
} else {
- if _, err := buf.WriteString(fmt.Sprintf(` SELECT "%s".* FROM `, t.Table)); err != nil {
+ if _, err := fmt.Fprintf(&buf, ` SELECT "%s".* FROM `, t.Table); err != nil {
return nil, errors.Wrap(err, "failed to write to buffer")
}
}
diff --git a/backend/plugin/parser/tidb/backup.go b/backend/plugin/parser/tidb/backup.go
index 0290c07400..5282e666d8 100644
--- a/backend/plugin/parser/tidb/backup.go
+++ b/backend/plugin/parser/tidb/backup.go
@@ -108,11 +108,11 @@ func generateSQLForSingleTable(ctx context.Context, tCtx base.TransformContext,
targetTable := fmt.Sprintf("%s_%s_%s", tablePrefix, table.Table, table.Database)
targetTable, _ = common.TruncateString(targetTable, maxTableNameLength)
var buf strings.Builder
- if _, err := buf.WriteString(fmt.Sprintf("CREATE TABLE `%s`.`%s` LIKE `%s`.`%s`;\n", databaseName, targetTable, table.Database, table.Table)); err != nil {
+ if _, err := fmt.Fprintf(&buf, "CREATE TABLE `%s`.`%s` LIKE `%s`.`%s`;\n", databaseName, targetTable, table.Database, table.Table); err != nil {
return nil, errors.Wrap(err, "failed to write create table statement")
}
- if _, err := buf.WriteString(fmt.Sprintf("INSERT INTO `%s`.`%s`", databaseName, targetTable)); err != nil {
+ if _, err := fmt.Fprintf(&buf, "INSERT INTO `%s`.`%s`", databaseName, targetTable); err != nil {
return nil, errors.Wrap(err, "failed to write insert into statement")
}
if len(generatedColumns) > 0 {
@@ -125,7 +125,7 @@ func generateSQLForSingleTable(ctx context.Context, tCtx base.TransformContext,
return nil, errors.Wrap(err, "failed to write comma")
}
}
- if _, err := buf.WriteString(fmt.Sprintf("`%s`", column)); err != nil {
+ if _, err := fmt.Fprintf(&buf, "`%s`", column); err != nil {
return nil, errors.Wrap(err, "failed to write column")
}
}
@@ -144,7 +144,7 @@ func generateSQLForSingleTable(ctx context.Context, tCtx base.TransformContext,
tableNameOrAlias = item.table.Alias
}
if len(generatedColumns) == 0 {
- if _, err := buf.WriteString(fmt.Sprintf(" SELECT `%s`.* FROM ", tableNameOrAlias)); err != nil {
+ if _, err := fmt.Fprintf(&buf, " SELECT `%s`.* FROM ", tableNameOrAlias); err != nil {
return nil, errors.Wrap(err, "failed to write select statement")
}
} else {
@@ -157,7 +157,7 @@ func generateSQLForSingleTable(ctx context.Context, tCtx base.TransformContext,
return nil, errors.Wrap(err, "failed to write comma")
}
}
- if _, err := buf.WriteString(fmt.Sprintf("`%s`.`%s`", tableNameOrAlias, column)); err != nil {
+ if _, err := fmt.Fprintf(&buf, "`%s`.`%s`", tableNameOrAlias, column); err != nil {
return nil, errors.Wrap(err, "failed to write column")
}
}
@@ -210,7 +210,7 @@ func generateSQLForMixedDML(ctx context.Context, tCtx base.TransformContext, sta
// If enforce_gtid_consistency = true on MySQL 5.6+, we cannot run CREATE TABLE .. AS SELECT.
// So we need to create the table first and then run INSERT INTO .. SELECT.
var buf strings.Builder
- if _, err := buf.WriteString(fmt.Sprintf("CREATE TABLE `%s`.`%s` LIKE `%s`.`%s`;\n", databaseName, targetTable, table.Database, table.Table)); err != nil {
+ if _, err := fmt.Fprintf(&buf, "CREATE TABLE `%s`.`%s` LIKE `%s`.`%s`;\n", databaseName, targetTable, table.Database, table.Table); err != nil {
return nil, errors.Wrap(err, "failed to write create table statement")
}
generatedColumns, normalColumns, err := classifyColumns(ctx, tCtx.GetDatabaseMetadataFunc, tCtx.ListDatabaseNamesFunc, tCtx.IsCaseSensitive, tCtx.InstanceID, table)
@@ -222,11 +222,11 @@ func generateSQLForMixedDML(ctx context.Context, tCtx base.TransformContext, sta
tableNameOrAlias = table.Alias
}
if len(generatedColumns) == 0 {
- if _, err := buf.WriteString(fmt.Sprintf("INSERT INTO `%s`.`%s` SELECT `%s`.* FROM ", databaseName, targetTable, tableNameOrAlias)); err != nil {
+ if _, err := fmt.Fprintf(&buf, "INSERT INTO `%s`.`%s` SELECT `%s`.* FROM ", databaseName, targetTable, tableNameOrAlias); err != nil {
return nil, errors.Wrap(err, "failed to write insert into statement")
}
} else {
- if _, err := buf.WriteString(fmt.Sprintf("INSERT INTO `%s`.`%s` (", databaseName, targetTable)); err != nil {
+ if _, err := fmt.Fprintf(&buf, "INSERT INTO `%s`.`%s` (", databaseName, targetTable); err != nil {
return nil, errors.Wrap(err, "failed to write insert into statement")
}
for i, column := range normalColumns {
@@ -235,7 +235,7 @@ func generateSQLForMixedDML(ctx context.Context, tCtx base.TransformContext, sta
return nil, errors.Wrap(err, "failed to write comma")
}
}
- if _, err := buf.WriteString(fmt.Sprintf("`%s`", column)); err != nil {
+ if _, err := fmt.Fprintf(&buf, "`%s`", column); err != nil {
return nil, errors.Wrap(err, "failed to write column")
}
}
@@ -248,7 +248,7 @@ func generateSQLForMixedDML(ctx context.Context, tCtx base.TransformContext, sta
return nil, errors.Wrap(err, "failed to write comma")
}
}
- if _, err := buf.WriteString(fmt.Sprintf("`%s`.`%s`", tableNameOrAlias, column)); err != nil {
+ if _, err := fmt.Fprintf(&buf, "`%s`.`%s`", tableNameOrAlias, column); err != nil {
return nil, errors.Wrap(err, "failed to write column")
}
}
diff --git a/backend/plugin/parser/tsql/backup.go b/backend/plugin/parser/tsql/backup.go
index 308deb3c65..9850176bbe 100644
--- a/backend/plugin/parser/tsql/backup.go
+++ b/backend/plugin/parser/tsql/backup.go
@@ -122,7 +122,7 @@ func generateSQLForTable(statementInfoList []statementInfo, targetDatabase strin
targetTable := fmt.Sprintf("%s_%s_%s", tablePrefix, table.Table, table.Database)
targetTable, _ = common.TruncateString(targetTable, maxTableNameLength)
var buf strings.Builder
- if _, err := buf.WriteString(fmt.Sprintf(`SELECT * INTO [%s].[%s].[%s] FROM (`+"\n", targetDatabase, defaultSchema, targetTable)); err != nil {
+ if _, err := fmt.Fprintf(&buf, "SELECT * INTO [%s].[%s].[%s] FROM (\n", targetDatabase, defaultSchema, targetTable); err != nil {
return nil, errors.Wrap(err, "failed to write buffer")
}
for i, item := range statementInfoList {
@@ -136,11 +136,11 @@ func generateSQLForTable(statementInfoList []statementInfo, targetDatabase strin
return nil, errors.Wrap(err, "failed to extract suffix select statement")
}
if len(item.table.Alias) == 0 {
- if _, err := buf.WriteString(fmt.Sprintf(` SELECT [%s].[%s].[%s].* `, item.table.Database, item.table.Schema, item.table.Table)); err != nil {
+ if _, err := fmt.Fprintf(&buf, " SELECT [%s].[%s].[%s].* ", item.table.Database, item.table.Schema, item.table.Table); err != nil {
return nil, errors.Wrap(err, "failed to write buffer")
}
} else {
- if _, err := buf.WriteString(fmt.Sprintf(` SELECT [%s].* `, item.table.Alias)); err != nil {
+ if _, err := fmt.Fprintf(&buf, " SELECT [%s].* ", item.table.Alias); err != nil {
return nil, errors.Wrap(err, "failed to write buffer")
}
}
diff --git a/backend/plugin/schema/mssql/generate_migration.go b/backend/plugin/schema/mssql/generate_migration.go
index 83e10aec71..3a425c99db 100644
--- a/backend/plugin/schema/mssql/generate_migration.go
+++ b/backend/plugin/schema/mssql/generate_migration.go
@@ -705,7 +705,7 @@ func generateColumnDefinition(column *storepb.ColumnMetadata) string {
// Add IDENTITY if applicable
if column.IsIdentity {
_, _ = buf.WriteString(" IDENTITY(")
- _, _ = buf.WriteString(fmt.Sprintf("%d,%d", column.IdentitySeed, column.IdentityIncrement))
+ _, _ = fmt.Fprintf(&buf, "%d,%d", column.IdentitySeed, column.IdentityIncrement)
_, _ = buf.WriteString(")")
}
diff --git a/backend/plugin/schema/pg/generate_migration.go b/backend/plugin/schema/pg/generate_migration.go
index 6d1beed0ea..ffaacaed3a 100644
--- a/backend/plugin/schema/pg/generate_migration.go
+++ b/backend/plugin/schema/pg/generate_migration.go
@@ -1401,7 +1401,7 @@ func generateAlterTableWithOptions(tableDiff *schema.TableDiff, includeColumnAdd
if indexAST, ok := indexDiff.NewASTNode.(*pgparser.IndexstmtContext); ok {
if err := writeCreateIndexFromAST(&buf, indexAST); err != nil {
// If AST extraction fails, log error but continue (non-fatal)
- _, _ = buf.WriteString(fmt.Sprintf("-- Error creating index: %v\n", err))
+ _, _ = fmt.Fprintf(&buf, "-- Error creating index: %v\n", err)
}
}
}
@@ -1419,7 +1419,7 @@ func generateAlterTableWithOptions(tableDiff *schema.TableDiff, includeColumnAdd
if constraintAST, ok := checkDiff.NewASTNode.(pgparser.ITableconstraintContext); ok {
if err := writeAddCheckConstraintFromAST(&buf, tableDiff.SchemaName, tableDiff.TableName, constraintAST); err != nil {
// If AST extraction fails, log error but continue (non-fatal)
- _, _ = buf.WriteString(fmt.Sprintf("-- Error adding check constraint: %v\n", err))
+ _, _ = fmt.Fprintf(&buf, "-- Error adding check constraint: %v\n", err)
}
}
}
@@ -1437,7 +1437,7 @@ func generateAlterTableWithOptions(tableDiff *schema.TableDiff, includeColumnAdd
if constraintAST, ok := excludeDiff.NewASTNode.(pgparser.ITableconstraintContext); ok {
if err := writeAddExcludeConstraintFromAST(&buf, tableDiff.SchemaName, tableDiff.TableName, constraintAST); err != nil {
// If AST extraction fails, log error but continue (non-fatal)
- _, _ = buf.WriteString(fmt.Sprintf("-- Error adding EXCLUDE constraint: %v\n", err))
+ _, _ = fmt.Fprintf(&buf, "-- Error adding EXCLUDE constraint: %v\n", err)
}
}
}
@@ -1455,7 +1455,7 @@ func generateAlterTableWithOptions(tableDiff *schema.TableDiff, includeColumnAdd
if constraintAST, ok := uniqueDiff.NewASTNode.(pgparser.ITableconstraintContext); ok {
if err := writeAddUniqueConstraintFromAST(&buf, tableDiff.SchemaName, tableDiff.TableName, constraintAST); err != nil {
// If AST extraction fails, log error but continue (non-fatal)
- _, _ = buf.WriteString(fmt.Sprintf("-- Error adding unique constraint: %v\n", err))
+ _, _ = fmt.Fprintf(&buf, "-- Error adding unique constraint: %v\n", err)
}
}
}
@@ -1473,7 +1473,7 @@ func generateAlterTableWithOptions(tableDiff *schema.TableDiff, includeColumnAdd
if constraintAST, ok := pkDiff.NewASTNode.(pgparser.ITableconstraintContext); ok {
if err := writeAddPrimaryKeyFromAST(&buf, tableDiff.SchemaName, tableDiff.TableName, constraintAST); err != nil {
// If AST extraction fails, log error but continue (non-fatal)
- _, _ = buf.WriteString(fmt.Sprintf("-- Error adding primary key constraint: %v\n", err))
+ _, _ = fmt.Fprintf(&buf, "-- Error adding primary key constraint: %v\n", err)
}
}
}
@@ -1499,7 +1499,7 @@ func generateAlterTableForeignKeys(tableDiff *schema.TableDiff) (string, error)
if constraintAST, ok := fkDiff.NewASTNode.(pgparser.ITableconstraintContext); ok {
if err := writeAddForeignKeyFromAST(&buf, tableDiff.SchemaName, tableDiff.TableName, constraintAST); err != nil {
// If AST extraction fails, log error but continue (non-fatal)
- _, _ = buf.WriteString(fmt.Sprintf("-- Error adding foreign key constraint: %v\n", err))
+ _, _ = fmt.Fprintf(&buf, "-- Error adding foreign key constraint: %v\n", err)
}
}
}
diff --git a/backend/plugin/schema/pg/walk_through.go b/backend/plugin/schema/pg/walk_through.go
index 35db916876..85288ac48d 100644
--- a/backend/plugin/schema/pg/walk_through.go
+++ b/backend/plugin/schema/pg/walk_through.go
@@ -1936,7 +1936,7 @@ func generateIndexName(tableName string, columnList []string, _ bool) string {
if col == "expr" {
builder.WriteString("expr")
if expressionID > 0 {
- builder.WriteString(fmt.Sprintf("%d", expressionID))
+ fmt.Fprintf(&builder, "%d", expressionID)
}
expressionID++
} else {
diff --git a/backend/plugin/webhook/feishu/feishu.go b/backend/plugin/webhook/feishu/feishu.go
index 44c1bd52b1..f82a97f626 100644
--- a/backend/plugin/webhook/feishu/feishu.go
+++ b/backend/plugin/webhook/feishu/feishu.go
@@ -226,17 +226,17 @@ func getMessageCard(context webhook.Context) *WebhookCard {
var markdownBuf strings.Builder
if context.Description != "" {
- _, _ = markdownBuf.WriteString(fmt.Sprintf("%s\n", context.Description))
+ _, _ = fmt.Fprintf(&markdownBuf, "%s\n", context.Description)
}
for _, meta := range context.GetMetaList() {
- _, _ = markdownBuf.WriteString(fmt.Sprintf("**%s**: %s\n", meta.Name, meta.Value))
+ _, _ = fmt.Fprintf(&markdownBuf, "**%s**: %s\n", meta.Name, meta.Value)
}
if context.ActorName != "" {
- _, _ = markdownBuf.WriteString(fmt.Sprintf("**Actor**: %s (%s)\n", context.ActorName, context.ActorEmail))
+ _, _ = fmt.Fprintf(&markdownBuf, "**Actor**: %s (%s)\n", context.ActorName, context.ActorEmail)
}
- _, _ = markdownBuf.WriteString(fmt.Sprintf("[View in Bytebase](%s)", context.Link))
+ _, _ = fmt.Fprintf(&markdownBuf, "[View in Bytebase](%s)", context.Link)
return &WebhookCard{
Config: WebhookCardConfig{
diff --git a/backend/plugin/webhook/lark/lark.go b/backend/plugin/webhook/lark/lark.go
index e2b5b760ff..5b3b8d87bf 100644
--- a/backend/plugin/webhook/lark/lark.go
+++ b/backend/plugin/webhook/lark/lark.go
@@ -226,17 +226,17 @@ func getMessageCard(context webhook.Context) *WebhookCard {
var markdownBuf strings.Builder
if context.Description != "" {
- _, _ = markdownBuf.WriteString(fmt.Sprintf("%s\n", context.Description))
+ _, _ = fmt.Fprintf(&markdownBuf, "%s\n", context.Description)
}
for _, meta := range context.GetMetaList() {
- _, _ = markdownBuf.WriteString(fmt.Sprintf("**%s**: %s\n", meta.Name, meta.Value))
+ _, _ = fmt.Fprintf(&markdownBuf, "**%s**: %s\n", meta.Name, meta.Value)
}
if context.ActorName != "" {
- _, _ = markdownBuf.WriteString(fmt.Sprintf("**Actor**: %s (%s)\n", context.ActorName, context.ActorEmail))
+ _, _ = fmt.Fprintf(&markdownBuf, "**Actor**: %s (%s)\n", context.ActorName, context.ActorEmail)
}
- _, _ = markdownBuf.WriteString(fmt.Sprintf("[View in Bytebase](%s)", context.Link))
+ _, _ = fmt.Fprintf(&markdownBuf, "[View in Bytebase](%s)", context.Link)
return &WebhookCard{
Config: WebhookCardConfig{
diff --git a/backend/store/issue.go b/backend/store/issue.go
index 7debda7b0c..34cea3df9f 100644
--- a/backend/store/issue.go
+++ b/backend/store/issue.go
@@ -454,7 +454,7 @@ func getTSVector(text string) string {
if i != 0 {
_, _ = tsVector.WriteString(" ")
}
- _, _ = tsVector.WriteString(fmt.Sprintf("%s:%d", part, i+1))
+ _, _ = fmt.Fprintf(&tsVector, "%s:%d", part, i+1)
}
return tsVector.String()
}
@@ -474,7 +474,7 @@ func getTSQuery(text string) string {
if i != 0 {
_, _ = tsQuery.WriteString("|")
}
- _, _ = tsQuery.WriteString(fmt.Sprintf("%s:*", part))
+ _, _ = fmt.Fprintf(&tsQuery, "%s:*", part)
}
return tsQuery.String()
}