From e47079f0f43bdd52adb0534c3c57b9fc9eea662c Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Sat, 17 Jul 2021 20:51:23 +0800 Subject: [PATCH] go format with extra rules (#821) --- tools/goctl/model/sql/gen/gen_test.go | 4 ++-- tools/goctl/model/sql/parser/parser_test.go | 6 +++--- tools/goctl/rpc/generator/gen_test.go | 1 - tools/goctl/rpc/generator/genlogic.go | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/tools/goctl/model/sql/gen/gen_test.go b/tools/goctl/model/sql/gen/gen_test.go index 38c59d34..b748641e 100644 --- a/tools/goctl/model/sql/gen/gen_test.go +++ b/tools/goctl/model/sql/gen/gen_test.go @@ -23,7 +23,7 @@ func TestCacheModel(t *testing.T) { _ = Clean() sqlFile := filepath.Join(t.TempDir(), "tmp.sql") - err := ioutil.WriteFile(sqlFile, []byte(source), 0777) + err := ioutil.WriteFile(sqlFile, []byte(source), 0o777) assert.Nil(t, err) dir := filepath.Join(t.TempDir(), "./testmodel") @@ -58,7 +58,7 @@ func TestNamingModel(t *testing.T) { _ = Clean() sqlFile := filepath.Join(t.TempDir(), "tmp.sql") - err := ioutil.WriteFile(sqlFile, []byte(source), 0777) + err := ioutil.WriteFile(sqlFile, []byte(source), 0o777) assert.Nil(t, err) dir, _ := filepath.Abs("./testmodel") diff --git a/tools/goctl/model/sql/parser/parser_test.go b/tools/goctl/model/sql/parser/parser_test.go index 02834cb1..b31dc232 100644 --- a/tools/goctl/model/sql/parser/parser_test.go +++ b/tools/goctl/model/sql/parser/parser_test.go @@ -12,7 +12,7 @@ import ( func TestParsePlainText(t *testing.T) { sqlFile := filepath.Join(t.TempDir(), "tmp.sql") - err := ioutil.WriteFile(sqlFile, []byte("plain text"), 0777) + err := ioutil.WriteFile(sqlFile, []byte("plain text"), 0o777) assert.Nil(t, err) _, err = Parse(sqlFile) @@ -21,7 +21,7 @@ func TestParsePlainText(t *testing.T) { func TestParseSelect(t *testing.T) { sqlFile := filepath.Join(t.TempDir(), "tmp.sql") - err := ioutil.WriteFile(sqlFile, []byte("select * from user"), 0777) + err := ioutil.WriteFile(sqlFile, []byte("select * from user"), 0o777) assert.Nil(t, err) tables, err := Parse(sqlFile) @@ -31,7 +31,7 @@ func TestParseSelect(t *testing.T) { func TestParseCreateTable(t *testing.T) { sqlFile := filepath.Join(t.TempDir(), "tmp.sql") - err := ioutil.WriteFile(sqlFile, []byte("CREATE TABLE `test_user` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `mobile` varchar(255) COLLATE utf8mb4_bin NOT NULL comment '手\\t机 号',\n `class` bigint NOT NULL comment '班级',\n `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL comment '姓\n 名',\n `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP comment '创建\\r时间',\n `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n PRIMARY KEY (`id`),\n UNIQUE KEY `mobile_unique` (`mobile`),\n UNIQUE KEY `class_name_unique` (`class`,`name`),\n KEY `create_index` (`create_time`),\n KEY `name_index` (`name`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;"), 0777) + err := ioutil.WriteFile(sqlFile, []byte("CREATE TABLE `test_user` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `mobile` varchar(255) COLLATE utf8mb4_bin NOT NULL comment '手\\t机 号',\n `class` bigint NOT NULL comment '班级',\n `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL comment '姓\n 名',\n `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP comment '创建\\r时间',\n `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n PRIMARY KEY (`id`),\n UNIQUE KEY `mobile_unique` (`mobile`),\n UNIQUE KEY `class_name_unique` (`class`,`name`),\n KEY `create_index` (`create_time`),\n KEY `name_index` (`name`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;"), 0o777) assert.Nil(t, err) tables, err := Parse(sqlFile) diff --git a/tools/goctl/rpc/generator/gen_test.go b/tools/goctl/rpc/generator/gen_test.go index 12bb6bdc..cd9ee2d0 100644 --- a/tools/goctl/rpc/generator/gen_test.go +++ b/tools/goctl/rpc/generator/gen_test.go @@ -74,7 +74,6 @@ func TestRpcGenerate(t *testing.T) { return strings.Contains(err.Error(), "not in GOROOT") || strings.Contains(err.Error(), "cannot find package") }()) } - }) // case not in go mod and go path diff --git a/tools/goctl/rpc/generator/genlogic.go b/tools/goctl/rpc/generator/genlogic.go index fe230cde..808b902c 100644 --- a/tools/goctl/rpc/generator/genlogic.go +++ b/tools/goctl/rpc/generator/genlogic.go @@ -83,7 +83,7 @@ func (g *DefaultGenerator) GenLogic(ctx DirContext, proto parser.Proto, cfg *con return nil } -func (g *DefaultGenerator) genLogicFunction(serviceName string, goPackage string, rpc *parser.RPC) (string, error) { +func (g *DefaultGenerator) genLogicFunction(serviceName, goPackage string, rpc *parser.RPC) (string, error) { functions := make([]string, 0) text, err := util.LoadTemplate(category, logicFuncTemplateFileFile, logicFunctionTemplate) if err != nil {