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
- Simplify project development and improve development efficiency.
- Support the accurate implementation of framework project design specifications.
Considerations
- Some commands require you to have a basic development environment for
Golang
installed. Please refer to the chapter Installation for details on environment installation. - 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:
# GoFrame CLI tool configuration.
gfcli:
gen:
dao:
- link: "mysql:root:12345678@tcp(127.0.0.1:3306)/test"
tables: "user"
removePrefix: "gf_"
descriptionTag: true
noModelComment: true
docker:
build: "-a amd64 -s linux -p temp"
tagPrefixes:
- ccr.ccs.tencentyun.com/xxx
- hkccr.ccs.tencentyun.com/xxx
- 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:
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.
$ gf
USAGE
gf COMMAND [OPTION]
COMMAND
env show current Golang environment variables
run running go codes with hot-compiled-like feature
gen automatically generate go files for dao/dto/entity/pb/pbentity...
init create and initialize an empty GoFrame project
pack packing any file/directory to a resource file, or a go file
build cross-building go project for lots of platforms
docker build docker image for current GoFrame project
install install gf binary to system (might need root/admin permission)
version show version information of current binary
OPTION
-y, --yes all yes for all command without prompt ask
-v, --version show version information of current binary
-d, --debug show internal detailed debugging information
-h, --help more information about this command
ADDITIONAL
Use "gf COMMAND -h" for details about a command.
Documents
📄️ Installation
Install 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 Check
Use 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 Upgrade
Use 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 Scaffold
Use 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-Compiling
Cross-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 Generating
6 items
📄️ Auto Compiling
When 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 Packing
This 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 Building
Use 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 Fix
The 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 Info
Use 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.