gomake is a tool built on Mage that offers cross-platform and multi-architecture compilation support. It also simplifies the process of starting, stopping, and monitoring services.
- Copy the following files from the current directory to the project's root directory, noting that there are 5 files to copy besides the
READMEfile:bootstrap.batbootstrap.shmagefile.gomagefile_unix.gomagefile_windows.go
- The project's root directory should contain three directories:
cmd,tools, andconfig.- The
cmddirectory is specifically for storing the startup code of applications that run as background services. - The
toolsdirectory is for storing the startup code of applications that run as tools (not as background services). - The
configdirectory is for storing configuration files.
- The
- The
cmdandtoolsdirectories can contain multiple subdirectories. For files containing amainfunction in themain package, they should be namedmain.go. For example:cmd/microservice-test/main.gotools/helloworld/main.go- All code should belong to the same project, and subdirectories should not use independent
go.modandgo.sumfiles.
- For Linux/Mac systems, execute the
bootstrap.shscript first. - For Windows systems, execute the
bootstrap.batscript first.
- Run
mageormage buildto compile the project. - After compilation, binary files will be generated in the
_output/bin/platforms/<operating system>/<architecture>directory, with the binary files named after the directory of the correspondingmain.go. For example:_output/bin/platforms/linux/amd64/microservice-test_output/bin/tools/linux/amd64/helloworld- Note: Binary files on the Windows platform will automatically have a
.exeextension added.
-
After completing the
magecompilation, the system will automatically generate astart-config.ymlfile specifying the configuration for services and tools, which you can edit. For example:serviceBinaries: microservice-test: 1 toolBinaries: - helloworld maxFileDescriptors: 10000
Note: Ensure that the service names and tool names match the names of the subdirectories under the cmd and tools directories. The number after the service name represents the number of instances of the service to start.
-
Run
mage startto start the services and tools.- Tools will execute synchronously, and if a tool fails (exits with a non-zero exit code), the entire start-up process will be interrupted.
- Services will start asynchronously.
For all tools, the following command format will be used to start: [absolute path to program] -i 0 -c [absolute directory of configuration file].
If the service instance count is set to n, then n instances of the service will be started, with each instance using the command format: [program path] -i [instance index] -c [configuration file directory], where the instance index ranges from 0 to n-1.
Note: This project only specifies the path of the configuration file and does not handle reading the content of the configuration file. This is done to support scenarios using multiple configuration files. Both the program and configuration file paths are automatically converted to absolute paths.
- Run
mage checkto check the status of services and the ports they are listening on. - Run
mage stopto stop the services. This command will send a stop signal to the services.

