A template repository for automating Go project setup and management using a Makefile.
To get started, follow these steps:
-
Clone the Repository:
git clone https://github.com/sss7526/go_maker.git <your-project> cd <your-project>
Replace
<your-new-project-name>with the desired name of your new project. -
Install Go (if not already installed): Run the following command to ensure the latest version of Go is installed on your system:
make install
-
Initialize Your New Project: Use the
mod-initcommand to initialize your project:make mod-init
This will:
- Generate a
go.modfile with your project's name. - Create a
main.gofile with a Hello World program. - Generate a
main_test.gofile to test the Hello World program. - Reinitialize the Git repository, unlinking it from the upstream template and starting with a fresh commit history.
- Generate a
You’re now ready to start building your Go project.
The repository's Makefile provides several commands to manage and maintain the project. Below is the output of make help
========================================================================================================
██████╗ ██████╗ ███╗ ███╗ █████╗ ██╗ ██╗███████╗██████╗
██╔════╝ ██╔═══██╗ ████╗ ████║██╔══██╗██║ ██╔╝██╔════╝██╔══██╗
██║ ███╗██║ ██║█████╗██╔████╔██║███████║█████╔╝ █████╗ ██████╔╝
██║ ██║██║ ██║╚════╝██║╚██╔╝██║██╔══██║██╔═██╗ ██╔══╝ ██╔══██╗
╚██████╔╝╚██████╔╝ ██║ ╚═╝ ██║██║ ██║██║ ██╗███████╗██║ ██║
╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
========================================================================================================
COMMANDS FOR GO PROJECT MANAGEMENT
========================================================================================================
SOURCE: https://github.com/sss7526/go_maker
SETUP AND MAINTENANCE:
install Install the latest Go version (if not installed).
update Update Go to the latest version (if needed).
uninstall Remove the currently installed Go version.
MODULE MANAGEMENT:
mod-init Initialize a new Go module in the current directory.
mod-tidy Ensure go.mod and go.sum are in a tidy state.
mod-update Update all project dependencies to their latest versions.
CODE QUALITY & SECURITY:
format Format Go files to a consistent standard (via gofmt).
lint Perform rigorous code linting with golangci-lint.
vulncheck Analyze dependencies for vulnerabilities (via govulncheck).
BUILD, RUN, & TEST:
run Run the project's main entry point (main.go)
test Run all tests recursively across all packages.
build Build the project and output the binary to ~/.local/bin/your_project.
build-dev Build the project in dev mode and output the binary to ~/.local/bin/your_project.
ex Execute the built binary.
clean Remove the compiled binary from ~/.local/bin/.
MISCELLANEOUS:
fix_certs Fix TLS certificate issues when working in WSL in Enterprise Windows environments.
tree Generate a directory structure summary and save it to tree.txt.
doctor Check for missing system utilities.
help Display this help screen.
========================================================================================================
INFO: Use 'make <target>' to run a command.
========================================================================================================
| Command | Description |
|---|---|
make install |
Installs the latest version of Go if it’s not already installed locally. |
make update |
Updates Go to the latest version. |
make uninstall |
Removes the currently installed Go versionn |
| Command | Description |
|---|---|
make mod-init |
Initializes a new Go project, generates boilerplate code, and reinitializes Git. |
make mod-tidy |
Ensures go.mod and go.sum are in a tidy, consistent state. |
make mod-update |
Updates all project dependencies to their latest compatible versions. |
| Command | Description |
|---|---|
make format |
Formats Go files using gofmt. |
make lint |
Performs static analysis and linting with golangci-lint. |
make vulncheck |
Checks for vulnerabilities in dependencies using govulncheck. |
| Command | Description |
|---|---|
make build |
Builds the Go project and places the binary in ~/.local/bin/<project-name>. |
make build-dev |
Builds the Go project in dev mode and places the binary in ~/.local/bin/<project-name>. |
make run [ARGS] |
Runs the main.go file of the project. Accepts arbitrary arguments |
make test |
Executes tests recursively (go test ./...). |
make ex |
Executes the built binary. |
make clean |
Removes the built binary. |
| Command | Description |
|---|---|
make fix_certs |
Fix TLS certificate issues when working in WSL in Enterprise Windows environments. |
make tree |
Generate a directory structure summary and save it to tree.txt |
make doctor |
Check for missing system utilities |
make help |
Shows help output |
This an example of the terminal output when running make mod-init:
Initializing Go module with name: my-project...
go.mod created.
Creating main.go with a Hello World program...
main.go created.
Creating main_test.go with a basic test...
main_test.go created.
The repository is currently linked to the template upstream (https://github.com/sss7526/go_maker.git).
Resetting .git and initializing a new Git repository...
Git repository has been reset and initialized.
After running make mod-init, your project will have the following structure:
<project-name>/
├── Makefile
├── go.mod
├── main.go
├── main_test.go
├── .gitignore
└── .git/
After running make mod-init, you will have your project's Git repository initialized with an empty commit history. To create your first commit, do the following:
git add .
git commit -m "Initial commit"If you want to link your project to a remote repository, run:
git remote add origin <your-new-repository-url>
git push -u origin mainContributions to this repository are welcome! If you have suggestions, feature requests, or improvements, please submit an issue or create a pull request.
This project is licensed under the MIT License.