diff --git a/cmd/gf/internal/cmd/cmd_gen_ctrl_test.go b/cmd/gf/internal/cmd/cmd_gen_ctrl_test.go index baab9f04dcc..88631402563 100644 --- a/cmd/gf/internal/cmd/cmd_gen_ctrl_test.go +++ b/cmd/gf/internal/cmd/cmd_gen_ctrl_test.go @@ -19,9 +19,10 @@ import ( func Test_Gen_Ctrl_Default(t *testing.T) { gtest.C(t, func(t *gtest.T) { var ( - path = gfile.Temp(guid.S()) - in = genctrl.CGenCtrlInput{ - SrcFolder: gtest.DataPath("genctrl", "api"), + path = gfile.Temp(guid.S()) + apiFolder = gtest.DataPath("genctrl", "api") + in = genctrl.CGenCtrlInput{ + SrcFolder: apiFolder, DstFolder: path, WatchFile: "", SdkPath: "", @@ -44,6 +45,13 @@ func Test_Gen_Ctrl_Default(t *testing.T) { panic(err) } + // apiInterface files + var ( + genApi = apiFolder + filepath.FromSlash("/article/article.go") + genApiExpect = apiFolder + filepath.FromSlash("/article/article_expect.go.txt") + ) + t.Assert(gfile.GetContents(genApi), gfile.GetContents(genApiExpect)) + // files files, err := gfile.ScanDir(path, "*.go", true) t.AssertNil(err) diff --git a/cmd/gf/internal/cmd/genctrl/genctrl_generate_interface.go b/cmd/gf/internal/cmd/genctrl/genctrl_generate_interface.go index 00e5df72235..c0ba77e1f8e 100644 --- a/cmd/gf/internal/cmd/genctrl/genctrl_generate_interface.go +++ b/cmd/gf/internal/cmd/genctrl/genctrl_generate_interface.go @@ -50,8 +50,7 @@ func (c *apiInterfaceGenerator) doGenerate(apiModuleFolderPath string, module st moduleFilePath = filepath.FromSlash(gfile.Join(apiModuleFolderPath, fmt.Sprintf(`%s.if.go`, module))) } // all import paths. - importPathMap.Set("\t"+`"context"`, 1) - importPathMap.Set("\t"+``, 1) + importPathMap.Set("\t"+`"context"`+"\n", 1) for _, item := range items { importPathMap.Set(fmt.Sprintf("\t"+`"%s"`, item.Import), 1) } diff --git a/cmd/gf/internal/cmd/testdata/genctrl/api/article/article_expect.go.txt b/cmd/gf/internal/cmd/testdata/genctrl/api/article/article_expect.go.txt index 3b5693f06ff..3fd16175238 100644 --- a/cmd/gf/internal/cmd/testdata/genctrl/api/article/article_expect.go.txt +++ b/cmd/gf/internal/cmd/testdata/genctrl/api/article/article_expect.go.txt @@ -12,10 +12,13 @@ import ( ) type IArticleV1 interface { + Create(ctx context.Context, req *v1.CreateReq) (res *v1.CreateRes, err error) + Update(ctx context.Context, req *v1.UpdateReq) (res *v1.UpdateRes, err error) GetList(ctx context.Context, req *v1.GetListReq) (res *v1.GetListRes, err error) GetOne(ctx context.Context, req *v1.GetOneReq) (res *v1.GetOneRes, err error) } type IArticleV2 interface { Create(ctx context.Context, req *v2.CreateReq) (res *v2.CreateRes, err error) + Update(ctx context.Context, req *v2.UpdateReq) (res *v2.UpdateRes, err error) } diff --git a/cmd/gf/internal/consts/consts_gen_ctrl_template.go b/cmd/gf/internal/consts/consts_gen_ctrl_template.go index b60ed81d1f5..1268dfc6592 100644 --- a/cmd/gf/internal/consts/consts_gen_ctrl_template.go +++ b/cmd/gf/internal/consts/consts_gen_ctrl_template.go @@ -16,7 +16,7 @@ package {Module} const TemplateGenCtrlControllerNewEmpty = ` // ================================================================================= -// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. // ================================================================================= package {Module} @@ -60,7 +60,7 @@ func (c *{CtrlName}) {MethodName}(ctx context.Context, req *{Version}.{MethodNam const TemplateGenCtrlApiInterface = ` // ================================================================================= -// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. // ================================================================================= package {Module}