make init # one-time setup make build # cross compile make test # run the race-enabled tests
This repository is a comprehensive template for building production-ready Go applications. It comes pre-configured with a suite of tools and workflows to enforce best practices, automate common development tasks, and streamline the CI/CD process.
To initialize a new project from this template, use the goinit script. This script automates the setup process.
Prerequisites:
- The
justcommand-line tool must be installed. You can find installation instructions at https://github.com/casey/just.
Initialization Steps:
-
Run the Initialization Script: Execute the
goinitscript from the.bindirectory, providing your desired project name.If you're using direnv, the
.bindirectory should already be in your PATH.
goinit <repository-name>For example:
goinit my-new-app- Activate Development Environment:
This project uses
direnvanddevboxto manage the development environment. After thegoinitscript completes, enable the environment by running:
direnv allowThis will install all necessary dependencies defined in devbox.json.
This project uses a justfile to provide a set of commands for automating common development tasks.
| Command | Description |
|---|---|
help |
Displays a list of all available just commands. |
deps |
Checks that all required dependencies are installed. |
clean |
Removes generated files and build artifacts. |
generate (or gen) |
Runs Go code generation and formats the code. |
lint |
Runs all linters on the codebase. |
lint-ci |
A CI-optimized linting command that only checks changed files. |
lint-fix |
Runs linters with the --fix flag to automatically correct issues. |
fmt |
Formats Go code. |
test |
Executes the Go test suite for all packages. |
test-race |
Runs tests with the Go race detector enabled. |
test-coverage |
Runs tests and generates a code coverage report. |
build |
A placeholder for building project components. |
version |
Displays the current project version based on the latest Git tag. |
devbox |
Installs the Devbox tool if it is not already present. |
shell |
Enters a devbox shell with all project dependencies. |
The repository is equipped with a CI/CD pipeline that automates testing, security analysis, and releases.
- Trigger: Runs on every push to
mainand on every pull request. - Process:
- Checks out the code.
- Sets up the Go environment.
- Runs code generation and tests.
- Uploads test results as a workflow artifact.
- Trigger: Runs on push to
mainand on pull requests. - Jobs:
- SAST (Static Application Security Testing): Uses
golangci-lintto perform static analysis. - SCA (Software Composition Analysis): Uses
govulncheckto scan for vulnerabilities in dependencies.
- SAST (Static Application Security Testing): Uses
- Trigger: Manual or on a
workflow_callwith a specified Git tag. - Process:
- Checks out the specified Git tag.
- Sets up Go, QEMU, and Docker Buildx.
- Logs into DockerHub.
- Runs
GoReleaserto build release artifacts, create a GitHub Release, and publish Docker images.