Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

oldme-git
Copy link
Member

@oldme-git oldme-git commented Jun 24, 2025

介绍

有时候某些项目没有达到要使用大仓模式的程度,使用单仓便可以完成业务。
但是gf gen ctrl 只能支持 module/version 这种目录,譬如 user/v1,像api/app/user/v1api/admin/admin/v1 这种接口便无能为力。

PR改进了生成模式,现在使其可以更灵活的生成控制器,包括多级目录生成。

例子

api 下定义了 appadmin 两个模块,其中 app 下又定义了 /user/v1/user/user_ext/v1,最后生成如红框所示:

image

这是一个复杂的例子,用来检测代码的健壮性。
在真实的项目中,应该类似 api/app/user/v1api/app/user_ext/v1

其他

  • 规范了一些测试用例,譬如本来的测试文件放在 /testdata/genctrl/testdata/genctrl-merge 中,现在更改为 /testdata/genctrl/default/testdata/genctrl/merge
  • 替换掉废弃的方法 gfile.Remove

增进来源:Issue和官网评论

@oldme-git oldme-git requested review from Copilot, gqcn and wln32 and removed request for gqcn and wln32 June 24, 2025 18:49
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the gf gen ctrl command to support nested/multi-level API directories and updates related test fixtures to match the new directory structure.

  • Introduces generateByModules for recursive module generation.
  • Updates testdata paths in unit tests (default and merge scenarios).
  • Replaces deprecated gfile.Remove calls with gfile.RemoveAll.

Reviewed Changes

Copilot reviewed 42 out of 50 changed files in this pull request and generated 3 comments.

File Description
cmd/gf/internal/cmd/genctrl/genctrl.go Added generateByModules to recursively process subfolders.
cmd/gf/internal/cmd/cmd_z_unit_gen_ctrl_test.go Adjusted test paths and cleanup to use RemoveAll.
cmd/gf/internal/cmd/testdata/genctrl/* Added/updated multi-level controller and API fixtures.

@fainc
Copy link
Contributor

fainc commented Jun 25, 2025

求改一下gen pb 目前只生成controller到一个文件

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants