From 02adcccbf4008776efcf9513764ffd2f89ec1b88 Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Mon, 9 Aug 2021 18:11:08 +0800 Subject: [PATCH] format code (#884) --- tools/goctl/model/sql/builderx/builder.go | 2 +- tools/goctl/model/sql/gen/keys.go | 2 +- .../goctl/model/sql/model/postgresqlmodel.go | 20 +++++++++---------- tools/goctl/model/sql/parser/parser.go | 4 ++-- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/tools/goctl/model/sql/builderx/builder.go b/tools/goctl/model/sql/builderx/builder.go index a50e8915..3c609194 100644 --- a/tools/goctl/model/sql/builderx/builder.go +++ b/tools/goctl/model/sql/builderx/builder.go @@ -122,7 +122,7 @@ func RawFieldNames(in interface{}, postgresSql ...bool) []string { } func PostgreSqlJoin(elems []string) string { - var b = new(strings.Builder) + b := new(strings.Builder) for index, e := range elems { b.WriteString(fmt.Sprintf("%s = $%d, ", e, index+1)) } diff --git a/tools/goctl/model/sql/gen/keys.go b/tools/goctl/model/sql/gen/keys.go index 9759c664..8e0c6b91 100644 --- a/tools/goctl/model/sql/gen/keys.go +++ b/tools/goctl/model/sql/gen/keys.go @@ -50,7 +50,7 @@ func genCacheKeys(table parser.Table) (Key, []Key) { return primaryKey, uniqueKey } -func genCacheKey(db stringx.String, table stringx.String, in []*parser.Field) Key { +func genCacheKey(db, table stringx.String, in []*parser.Field) Key { var ( varLeftJoin, varRightJon, fieldNameJoin Join varLeft, varRight, varExpression string diff --git a/tools/goctl/model/sql/model/postgresqlmodel.go b/tools/goctl/model/sql/model/postgresqlmodel.go index 2f8e6329..15390bfa 100644 --- a/tools/goctl/model/sql/model/postgresqlmodel.go +++ b/tools/goctl/model/sql/model/postgresqlmodel.go @@ -7,16 +7,14 @@ import ( "github.com/tal-tech/go-zero/core/stores/sqlx" ) -var ( - p2m = map[string]string{ - "int8": "bigint", - "numeric": "bigint", - "float8": "double", - "float4": "float", - "int2": "smallint", - "int4": "integer", - } -) +var p2m = map[string]string{ + "int8": "bigint", + "numeric": "bigint", + "float8": "double", + "float4": "float", + "int2": "smallint", + "int4": "integer", +} // PostgreSqlModel gets table information from information_schema、pg_catalog type PostgreSqlModel struct { @@ -173,7 +171,7 @@ func (m *PostgreSqlModel) getIndex(schema, table string) (map[string][]*DbIndex, if err != nil { return nil, err } - var index = make(map[string][]*DbIndex) + index := make(map[string][]*DbIndex) for _, e := range indexes { if e.IsPrimary.Bool { index[e.ColumnName.String] = append(index[e.ColumnName.String], &DbIndex{ diff --git a/tools/goctl/model/sql/parser/parser.go b/tools/goctl/model/sql/parser/parser.go index 233e3125..4327fc2d 100644 --- a/tools/goctl/model/sql/parser/parser.go +++ b/tools/goctl/model/sql/parser/parser.go @@ -47,7 +47,7 @@ type ( ) // Parse parses ddl into golang structure -func Parse(filename string, database string) ([]*Table, error) { +func Parse(filename, database string) ([]*Table, error) { p := parser.NewParser() tables, err := p.From(filename) if err != nil { @@ -146,7 +146,7 @@ func Parse(filename string, database string) ([]*Table, error) { list = append(list, &Table{ Name: stringx.From(e.Name), - Db: stringx.From(database), + Db: stringx.From(database), PrimaryKey: primaryKey, UniqueIndex: uniqueIndex, Fields: fields,