The GoFrame framework provides a powerful gf command line development assistance tool, which is an important part of the framework’s development. Tool link:

Please refer to the repository page for tool installation. Once the tool is successfully installed, you can view all supported commands with gf or gf -h. For complex commands, you can view more detailed usage information with gf COMMAND -h, for example: gf gen -h.

Tool Responsibilities

  1. Simplify project development and improve development efficiency.
  2. Support the accurate implementation of framework project design specifications.

Considerations

  1. Some commands require you to have a basic development environment for Golang installed. Please refer to the chapter Installation for details on environment installation.
  2. The latest version of the CLI tool will follow the latest version of the framework.

Configuration Support

All commands of the tool support configuration parameters through both command line and configuration file simultaneously to improve usability. Command line parameters take precedence; if they are not provided, the tool automatically reads the corresponding parameter names from the configuration file.

The configuration file path prioritizes the hack directory in the current directory (hack/config.yaml), and then the framework’s default configuration path. For the framework’s default configuration file retrieval path, please refer to the chapter: Configuration - File.

Example configuration file format:

  1. # GoFrame CLI tool configuration.
  2. gfcli:
  3. gen:
  4. dao:
  5. - link: "mysql:root:12345678@tcp(127.0.0.1:3306)/test"
  6. tables: "user"
  7. removePrefix: "gf_"
  8. descriptionTag: true
  9. noModelComment: true
  10. docker:
  11. build: "-a amd64 -s linux -p temp"
  12. tagPrefixes:
  13. - ccr.ccs.tencentyun.com/xxx
  14. - hkccr.ccs.tencentyun.com/xxx
  15. - sgccr.ccs.tencentyun.com/xxx

Note that the above configuration example is for reference only. Please refer to specific command help for specific configuration items.

Tool Debugging

When encountering issues during the tool’s usage, you can try enabling the tool’s debug mode to obtain more detailed execution log information. The debug mode can be enabled with the debug command line option, for example:

  1. gf build main.go --debug

Since the gf tool is also developed using the GoFrame framework, the enabling of debug information is consistent with the framework method. For a more detailed introduction, please refer to the framework introduction document: Debug Mode

Command Overview

This help document uses gf cli v2.0.0 as an example for a brief introduction. For detailed introduction information, please refer to the command line help. The information in this chapter may be delayed, so please refer to the tool help for the latest specific introductions.

  1. $ gf
  2. USAGE
  3. gf COMMAND [OPTION]
  4. COMMAND
  5. env show current Golang environment variables
  6. run running go codes with hot-compiled-like feature
  7. gen automatically generate go files for dao/dto/entity/pb/pbentity...
  8. init create and initialize an empty GoFrame project
  9. pack packing any file/directory to a resource file, or a go file
  10. build cross-building go project for lots of platforms
  11. docker build docker image for current GoFrame project
  12. install install gf binary to system (might need root/admin permission)
  13. version show version information of current binary
  14. OPTION
  15. -y, --yes all yes for all command without prompt ask
  16. -v, --version show version information of current binary
  17. -d, --debug show internal detailed debugging information
  18. -h, --help more information about this command
  19. ADDITIONAL
  20. Use "gf COMMAND -h" for details about a command.

Documentation

📄️ InstallationInstall GoFrame tools on different operating systems, including installation methods for MacOS and Windows. Provides download links for precompiled binary files and methods for installation via the go install command, ensuring the gf tool is correctly installed and used in system environment variables.

📄️ Version CheckUse GoFrame command line tool to check version information, including usage of gf -v and gf version. The content covers examples of different version uses, showing specific version information of GoFrame in projects, explaining CLI compilation details and notes, to help users accurately understand the relationship between GoFrame version and Golang and related technologies.

📄️ Version UpgradeUse the GoFrame framework’s gf up command for version upgrades. The gf up command can update both the main framework and the CLI tool versions and automatically fix incompatible code changes during the upgrade process. This article provides detailed usage, command options, and examples to help users complete the upgrade process safely and efficiently.

📄️ Project ScaffoldUse the gf init command provided by the GoFrame framework to create a project. Starting from version v2, project creation is faster and no longer relies on remote sources; templates are built into the binary files. You can choose to initialize a single repository or monorepo project mode and flexibly adjust the generated directory structure to suit actual business needs.

📄️ Cross-CompilingCross-compilation using the GoFrame framework. With the gf build command, you can quickly generate an executable file that includes information such as the current Go version, GoFrame version, Git Commit, and more. Supports specifying parameters from both the command line and configuration files, meeting the compilation needs for different operating systems and platforms, providing developers with a convenient build solution.

🗃️ Code Generating6 items

📄️ Auto CompilingWhen building a project with the GoFrame framework, learn how to achieve automatic compilation through the gf run command. Although Go language does not inherently support hot compilation features, the gf run command can automatically compile and run a new version of the program when go files in the project change, aiming to improve development efficiency.

📄️ Resource PackingThis document introduces how to use the gf pack command in the GoFrame framework to package any file into a resource file or Go code file. Through this tool, users can achieve resource packaging and distribute it along with the executable file. Additionally, the gf pack command can be combined with the build command to achieve packaging and compiling in one step. The document provides a detailed list of usage methods and option explanations to help users better understand and use this feature.

📄️ Image BuildingUse the gf docker command of the GoFrame framework to compile and generate Docker images. After version 2.5, it is recommended to use gf build, gf gen enums, gf docker commands together through Makefile scripts for more flexibility and easier maintenance. Detailed examples and configuration file management suggestions are provided in the text.

📄️ Compatibility FixThe compatibility fix command gf fix provided by the GoFrame framework helps solve backward compatibility issues during framework upgrades. This command has been available since version v2.3, and automatically updates local code to handle minor compatibility issues. It can be executed repeatedly to ensure no side effects.

📄️ Help InfoUse the help command of the CLI tool of the GoFrame framework to get help information by entering gf -h or gf [COMMAND] -h. If you encounter any problems during use, you can always use the help command to query relevant assistance. Here, you can also learn about the specific information related to the sidebar position.