Project Scaffold - 图1tip

Starting from version v2, project creation no longer relies on remote retrieval. The repository templates are embedded into the tool’s binary files via Resource, making project creation very fast.

Usage

  1. $ gf init -h
  2. USAGE
  3. gf init ARGUMENT [OPTION]
  4. ARGUMENT
  5. NAME The project name, creating a folder named NAME in the current directory, and the module name will also be NAME
  6. OPTION
  7. -m, --mono Initialize monorepo mode
  8. -a, --monoApp Initialize a small repository under monorepo
  9. -u, --update Use the latest framework version after initialization
  10. -g, --module Customize module
  11. -h, --help More help
  12. EXAMPLE
  13. gf init my-project
  14. gf init my-mono-repo -m

We can use the init command to generate a sample GoFrame empty framework project in the current directory and provide a project name parameter. The generated project directory structure is for reference only and can be adjusted according to the specific situation of the business project. For the generated directory structure, please refer to the Code Layering section.

Project Scaffold - 图2note

The GoFrame framework development recommends the unified use of the official go module feature for dependency package management, so there is also a go.mod file in the root directory of the empty project.

Project Scaffold - 图3tip

The project directory uses a generalized design, and in actual projects, you can increase or decrease the directories given by the template as needed. For example, in scenarios where there is no need for kubernetes deployment, simply delete the corresponding deploy directory.

Examples of Use

Initialize a project in the current directory

  1. $ gf init .
  2. initializing...
  3. initialization done!
  4. you can now run 'gf run main.go' to start your journey, enjoy!

Create a project with a specified name

  1. $ gf init myapp
  2. initializing...
  3. initialization done!
  4. you can now run 'cd myapp && gf run main.go' to start your journey, enjoy!

Create a MonoRepo project

By default, a SingleRepo project is created, but if needed, you can also create a MonoRepo project by using the -m option.

  1. $ gf init mymono -m
  2. initializing...
  3. initialization done!

For an introduction to monorepos, please refer to the section: Mono-Repo Management

Create a MonoRepoApp project

If you need to create a small repository under a MonoRepo, specify the project path to be generated in the root directory of the repository project and use the -a option.

  1. $ gf init app/user -a
  2. initializing...
  3. initialization done!