refactor(cmd/gf): improve code structure for readability and maintainability#4771
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates gf init project generation to preserve local template imports and refreshes the bundled templates used by the CLI, addressing initialization failures where generated projects could not compile due to missing v1 imports.
Changes:
- Replaces built-in template formatting with
go/formatvia exportedgeninit.FormatGoFiles. - Refreshes packed template resources for single, mono, and mono-app templates.
- Updates Makefile packing flow and uses
perlfor cross-platform template text replacement.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
Makefile |
Runs cmd/gf template packing during version updates. |
cmd/gf/Makefile |
Switches mono-app template replacement from sed to perl. |
cmd/gf/internal/packed/template-single.go |
Refreshes packed single-project template resource. |
cmd/gf/internal/packed/template-mono.go |
Refreshes packed mono-repo template resource. |
cmd/gf/internal/packed/template-mono-app.go |
Refreshes packed mono-app template resource. |
cmd/gf/internal/cmd/geninit/geninit_generator.go |
Exports FormatGoFiles and uses it during remote template generation. |
cmd/gf/internal/cmd/cmd_init.go |
Uses FormatGoFiles for built-in template generation to avoid goimports import rewriting. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
gqcn
approved these changes
May 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refactor the code structure to enhance readability and maintainability without altering functionality.
fixed #4750 #4757 #4767
另外使用
gf init -r github.com/gogf/template-single my-project方式没有问题合并后v2.10.2生效