diff --git a/tools/goctl/api/format/format.go b/tools/goctl/api/format/format.go index e4366545..e9fb9dde 100644 --- a/tools/goctl/api/format/format.go +++ b/tools/goctl/api/format/format.go @@ -14,7 +14,7 @@ import ( "github.com/tal-tech/go-zero/core/errorx" "github.com/tal-tech/go-zero/tools/goctl/api/parser" "github.com/tal-tech/go-zero/tools/goctl/api/util" - ctlutil "github.com/tal-tech/go-zero/tools/goctl/util/pathx" + "github.com/tal-tech/go-zero/tools/goctl/util/pathx" "github.com/urfave/cli" ) @@ -124,7 +124,7 @@ func apiFormat(data string, filename ...string) (string, error) { newLineCount++ } else { if preLine == rightBrace { - builder.WriteString(ctlutil.NL) + builder.WriteString(pathx.NL) } newLineCount = 0 } @@ -152,7 +152,7 @@ func apiFormat(data string, filename ...string) (string, error) { } } util.WriteIndent(&builder, tapCount) - builder.WriteString(line + ctlutil.NL) + builder.WriteString(line + pathx.NL) if strings.HasSuffix(noCommentLine, leftParenthesis) || strings.HasSuffix(noCommentLine, leftBrace) { tapCount++ } @@ -168,10 +168,10 @@ func formatGoTypeDef(line string, scanner *bufio.Scanner, builder *strings.Build if strings.HasPrefix(noCommentLine, "type") && (strings.HasSuffix(noCommentLine, leftParenthesis) || strings.HasSuffix(noCommentLine, leftBrace)) { var typeBuilder strings.Builder - typeBuilder.WriteString(mayInsertStructKeyword(line, &tokenCount) + ctlutil.NL) + typeBuilder.WriteString(mayInsertStructKeyword(line, &tokenCount) + pathx.NL) for scanner.Scan() { noCommentLine := util.RemoveComment(scanner.Text()) - typeBuilder.WriteString(mayInsertStructKeyword(scanner.Text(), &tokenCount) + ctlutil.NL) + typeBuilder.WriteString(mayInsertStructKeyword(scanner.Text(), &tokenCount) + pathx.NL) if noCommentLine == rightBrace || noCommentLine == rightParenthesis { tokenCount-- } diff --git a/tools/goctl/api/gogen/genlogic.go b/tools/goctl/api/gogen/genlogic.go index c611ad38..baa62f17 100644 --- a/tools/goctl/api/gogen/genlogic.go +++ b/tools/goctl/api/gogen/genlogic.go @@ -10,7 +10,7 @@ import ( "github.com/tal-tech/go-zero/tools/goctl/api/spec" "github.com/tal-tech/go-zero/tools/goctl/config" "github.com/tal-tech/go-zero/tools/goctl/util/format" - ctlutil "github.com/tal-tech/go-zero/tools/goctl/util/pathx" + "github.com/tal-tech/go-zero/tools/goctl/util/pathx" "github.com/tal-tech/go-zero/tools/goctl/vars" ) @@ -113,9 +113,9 @@ func getLogicFolderPath(group spec.Group, route spec.Route) string { func genLogicImports(route spec.Route, parentPkg string) string { var imports []string imports = append(imports, `"context"`+"\n") - imports = append(imports, fmt.Sprintf("\"%s\"", ctlutil.JoinPackages(parentPkg, contextDir))) + imports = append(imports, fmt.Sprintf("\"%s\"", pathx.JoinPackages(parentPkg, contextDir))) if shallImportTypesPackage(route) { - imports = append(imports, fmt.Sprintf("\"%s\"\n", ctlutil.JoinPackages(parentPkg, typesDir))) + imports = append(imports, fmt.Sprintf("\"%s\"\n", pathx.JoinPackages(parentPkg, typesDir))) } imports = append(imports, fmt.Sprintf("\"%s/core/logx\"", vars.ProjectOpenSourceURL)) return strings.Join(imports, "\n\t") diff --git a/tools/goctl/api/gogen/genmain.go b/tools/goctl/api/gogen/genmain.go index 30076d7c..460eae97 100644 --- a/tools/goctl/api/gogen/genmain.go +++ b/tools/goctl/api/gogen/genmain.go @@ -7,7 +7,7 @@ import ( "github.com/tal-tech/go-zero/tools/goctl/api/spec" "github.com/tal-tech/go-zero/tools/goctl/config" "github.com/tal-tech/go-zero/tools/goctl/util/format" - ctlutil "github.com/tal-tech/go-zero/tools/goctl/util/pathx" + "github.com/tal-tech/go-zero/tools/goctl/util/pathx" "github.com/tal-tech/go-zero/tools/goctl/vars" ) @@ -68,9 +68,9 @@ func genMain(dir, rootPkg string, cfg *config.Config, api *spec.ApiSpec) error { func genMainImports(parentPkg string) string { var imports []string - imports = append(imports, fmt.Sprintf("\"%s\"", ctlutil.JoinPackages(parentPkg, configDir))) - imports = append(imports, fmt.Sprintf("\"%s\"", ctlutil.JoinPackages(parentPkg, handlerDir))) - imports = append(imports, fmt.Sprintf("\"%s\"\n", ctlutil.JoinPackages(parentPkg, contextDir))) + imports = append(imports, fmt.Sprintf("\"%s\"", pathx.JoinPackages(parentPkg, configDir))) + imports = append(imports, fmt.Sprintf("\"%s\"", pathx.JoinPackages(parentPkg, handlerDir))) + imports = append(imports, fmt.Sprintf("\"%s\"\n", pathx.JoinPackages(parentPkg, contextDir))) imports = append(imports, fmt.Sprintf("\"%s/core/conf\"", vars.ProjectOpenSourceURL)) imports = append(imports, fmt.Sprintf("\"%s/rest\"", vars.ProjectOpenSourceURL)) return strings.Join(imports, "\n\t") diff --git a/tools/goctl/api/gogen/gensvc.go b/tools/goctl/api/gogen/gensvc.go index 8400d607..a6764c8b 100644 --- a/tools/goctl/api/gogen/gensvc.go +++ b/tools/goctl/api/gogen/gensvc.go @@ -7,7 +7,7 @@ import ( "github.com/tal-tech/go-zero/tools/goctl/api/spec" "github.com/tal-tech/go-zero/tools/goctl/config" "github.com/tal-tech/go-zero/tools/goctl/util/format" - ctlutil "github.com/tal-tech/go-zero/tools/goctl/util/pathx" + "github.com/tal-tech/go-zero/tools/goctl/util/pathx" "github.com/tal-tech/go-zero/tools/goctl/vars" ) @@ -50,9 +50,9 @@ func genServiceContext(dir, rootPkg string, cfg *config.Config, api *spec.ApiSpe fmt.Sprintf("middleware.New%s().%s", strings.Title(name), "Handle")) } - configImport := "\"" + ctlutil.JoinPackages(rootPkg, configDir) + "\"" + configImport := "\"" + pathx.JoinPackages(rootPkg, configDir) + "\"" if len(middlewareStr) > 0 { - configImport += "\n\t\"" + ctlutil.JoinPackages(rootPkg, middlewareDir) + "\"" + configImport += "\n\t\"" + pathx.JoinPackages(rootPkg, middlewareDir) + "\"" configImport += fmt.Sprintf("\n\t\"%s/rest\"", vars.ProjectOpenSourceURL) } diff --git a/tools/goctl/api/gogen/util.go b/tools/goctl/api/gogen/util.go index 65f98679..3eef54ba 100644 --- a/tools/goctl/api/gogen/util.go +++ b/tools/goctl/api/gogen/util.go @@ -13,7 +13,7 @@ import ( "github.com/tal-tech/go-zero/tools/goctl/api/spec" "github.com/tal-tech/go-zero/tools/goctl/api/util" "github.com/tal-tech/go-zero/tools/goctl/util/ctx" - ctlutil "github.com/tal-tech/go-zero/tools/goctl/util/pathx" + "github.com/tal-tech/go-zero/tools/goctl/util/pathx" ) type fileGenConfig struct { @@ -41,7 +41,7 @@ func genFile(c fileGenConfig) error { if len(c.category) == 0 || len(c.templateFile) == 0 { text = c.builtinTemplate } else { - text, err = ctlutil.LoadTemplate(c.category, c.templateFile, c.builtinTemplate) + text, err = pathx.LoadTemplate(c.category, c.templateFile, c.builtinTemplate) if err != nil { return err } @@ -73,7 +73,7 @@ func getParentPackage(dir string) (string, error) { // fix https://github.com/zeromicro/go-zero/issues/1058 wd := projectCtx.WorkDir d := projectCtx.Dir - same, err := ctlutil.SameFile(wd, d) + same, err := pathx.SameFile(wd, d) if err != nil { return "", err } diff --git a/tools/goctl/go.mod b/tools/goctl/go.mod index c831cd7f..c3302f6f 100644 --- a/tools/goctl/go.mod +++ b/tools/goctl/go.mod @@ -10,7 +10,7 @@ require ( github.com/iancoleman/strcase v0.2.0 github.com/logrusorgru/aurora v2.0.3+incompatible github.com/stretchr/testify v1.7.0 - github.com/tal-tech/go-zero v1.2.5-0.20211230062155-e4ab51857606 + github.com/tal-tech/go-zero v1.2.5 github.com/urfave/cli v1.22.5 github.com/zeromicro/antlr v0.0.1 github.com/zeromicro/ddl-parser v0.0.0-20210712021150-63520aca7348 diff --git a/tools/goctl/go.sum b/tools/goctl/go.sum index c257cdf3..48557118 100644 --- a/tools/goctl/go.sum +++ b/tools/goctl/go.sum @@ -349,8 +349,8 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/tal-tech/go-zero v1.2.5-0.20211230062155-e4ab51857606 h1:u6Nm/S8pOqHDdjYs8aFBxDGC1BfjVmJoOus4g2RanZE= -github.com/tal-tech/go-zero v1.2.5-0.20211230062155-e4ab51857606/go.mod h1:OM2UangPHFMJ+5boRUaeQ/z6xpVvqprZda/JUWG1D7Y= +github.com/tal-tech/go-zero v1.2.5 h1:DpqTM/OTCThRtJoQPlp6b4/YnbCVkZ3gDT7+nFGUo3k= +github.com/tal-tech/go-zero v1.2.5/go.mod h1:OM2UangPHFMJ+5boRUaeQ/z6xpVvqprZda/JUWG1D7Y= github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU= github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= diff --git a/tools/goctl/model/sql/parser/parser_test.go b/tools/goctl/model/sql/parser/parser_test.go index 72898f87..a1c9574a 100644 --- a/tools/goctl/model/sql/parser/parser_test.go +++ b/tools/goctl/model/sql/parser/parser_test.go @@ -8,11 +8,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/tal-tech/go-zero/tools/goctl/model/sql/model" "github.com/tal-tech/go-zero/tools/goctl/model/sql/util" - ctlutil "github.com/tal-tech/go-zero/tools/goctl/util/pathx" + "github.com/tal-tech/go-zero/tools/goctl/util/pathx" ) func TestParsePlainText(t *testing.T) { - sqlFile := filepath.Join(ctlutil.MustTempDir(), "tmp.sql") + sqlFile := filepath.Join(pathx.MustTempDir(), "tmp.sql") err := ioutil.WriteFile(sqlFile, []byte("plain text"), 0o777) assert.Nil(t, err) @@ -21,7 +21,7 @@ func TestParsePlainText(t *testing.T) { } func TestParseSelect(t *testing.T) { - sqlFile := filepath.Join(ctlutil.MustTempDir(), "tmp.sql") + sqlFile := filepath.Join(pathx.MustTempDir(), "tmp.sql") err := ioutil.WriteFile(sqlFile, []byte("select * from user"), 0o777) assert.Nil(t, err) @@ -31,7 +31,7 @@ func TestParseSelect(t *testing.T) { } func TestParseCreateTable(t *testing.T) { - sqlFile := filepath.Join(ctlutil.MustTempDir(), "tmp.sql") + sqlFile := filepath.Join(pathx.MustTempDir(), "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;"), 0o777) assert.Nil(t, err)