Go Project Guardrails
Enforce Go-specific project standards including module configuration, Go version requirements, test execution scope, and vendoring policies.
golang to your lunar-config.yml:uses: github://earthly/lunar-lib/policies/golang@v1.0.0
Included Guardrails
This policy includes 6 guardrails that enforce standards for your devex build and ci.
go-mod-exists
Ensures the project has a go.mod file for module management. Required for all Go projects using modules.
go-sum-exists
Ensures the project has a go.sum file for dependency verification. Required for reproducible builds.
min-go-version
Ensures the project uses at least the minimum required Go version. Helps maintain security and compatibility standards.
min-go-version-cicd
Ensures the Go version used in CI/CD commands meets the minimum required version. Helps maintain security and compatibility standards for build environments.
tests-recursive
Ensures tests run recursively (./...) to cover all packages. Prevents accidentally missing tests in subpackages.
vendoring
Enforces vendoring policy - can require vendor directory exists or forbid it, depending on team standards.
How Guardrails Fit into Lunar
Lunar guardrails define your engineering standards as code. They evaluate data collected by integrations and produce pass/fail checks with actionable feedback.
Policies support gradual enforcement—from silent scoring to blocking PRs or deployments—letting you roll out standards at your own pace without disrupting existing workflows.
Learn How Lunar Works →Required Integrations
This policy evaluates data gathered by one or more of the following integration(s).
Make sure to enable them in your lunar-config.yml.
Configuration
Configure this policy in your lunar-config.yml.
Inputs
| Input | Required | Default | Description |
|---|---|---|---|
min_go_version
|
Optional |
1.21
|
Minimum required Go version (e.g., "1.21", "1.22") |
min_go_version_cicd
|
Optional |
1.21
|
Minimum required Go version for CI/CD commands (e.g., "1.21", "1.22") |
vendoring_mode
|
Optional |
none
|
Vendoring enforcement mode: - "required": Fail if vendor/ directory doesn't exist - "forbidden": Fail if vendor/ directory exists - "none": Skip vendoring check (default) |
Documentation
View on GitHubGo Project Guardrails
Enforce Go-specific project standards including module configuration, Go version requirements, test execution scope, and vendoring policies.
Overview
This policy validates Go projects against best practices for module management and project structure. It ensures projects have proper go.mod and go.sum files, use a minimum Go version, run tests recursively to cover all packages, and follow your team's vendoring standards.
Policies
This plugin provides the following policies (use include to select a subset):
| Policy | Description | Failure Meaning |
|---|---|---|
go-mod-exists |
Validates go.mod exists | Project lacks module definition |
go-sum-exists |
Validates go.sum exists | Missing dependency checksums |
min-go-version |
Ensures minimum Go version in go.mod | Go version too old |
min-go-version-cicd |
Ensures minimum Go version in CI/CD | CI/CD Go version too old |
tests-recursive |
Ensures tests run with ./... |
Tests may miss subpackages |
vendoring |
Enforces vendoring policy | Vendor dir present/absent per policy |
Required Data
This policy reads from the following Component JSON paths:
| Path | Type | Provided By |
|---|---|---|
.lang.go |
object | golang collector |
.lang.go.native.go_mod.exists |
boolean | golang collector |
.lang.go.native.go_sum.exists |
boolean | golang collector |
.lang.go.version |
string | golang collector |
.lang.go.tests.scope |
string | golang collector |
.lang.go.cicd.cmds |
array | golang collector |
.lang.go.native.vendor.exists |
boolean | golang collector |
Installation
Add to your lunar-config.yml:
policies:
- uses: github://earthly/lunar-lib/policies/golang@v1.0.0
on: [go] # Or use tags like ["domain:backend"]
enforcement: report-pr
# include: [go-mod-exists, go-sum-exists] # Only run specific checks
with:
min_go_version: "1.21" # Minimum required Go version in go.mod (default: "1.21")
min_go_version_cicd: "1.21" # Minimum Go version for CI/CD commands (default: "1.21")
vendoring_mode: "none" # "required", "forbidden", or "none" (default: "none")
Examples
Passing Example
{
"lang": {
"go": {
"module": "github.com/acme/myproject",
"version": "1.22",
"native": {
"go_mod": { "exists": true },
"go_sum": { "exists": true },
"vendor": { "exists": false }
},
"tests": {
"scope": "recursive"
}
}
}
}
Failing Example
{
"lang": {
"go": {
"version": "1.19",
"native": {
"go_mod": { "exists": false },
"go_sum": { "exists": false }
}
}
}
}
Failure messages:
"go.mod not found. Initialize with 'go mod init <module-path>'""go.sum not found. Run 'go mod tidy' to generate checksums.""Go version 1.19 is below minimum 1.21. Update go.mod to require Go 1.21 or higher."
Remediation
go-mod-exists
- Run
go mod init <module-path>to create a go.mod file - The module path should match your repository URL (e.g.,
github.com/org/repo)
go-sum-exists
- Run
go mod tidyto generate the go.sum file - Commit the go.sum file to version control
min-go-version
- Update the
godirective in your go.mod file:go 1.21 - Run
go mod tidyto update dependencies - Test your code with the new Go version
min-go-version-cicd
- Update your CI/CD pipeline to use a newer Go version
- For GitHub Actions: update
go-versionin your workflow - For Docker-based builds: update your base Go image version
tests-recursive
- Update your CI configuration to run
go test ./...instead of targeting specific packages - This ensures all packages and subpackages are tested
vendoring
- If
vendoring_mode: required: Rungo mod vendorto create the vendor directory - If
vendoring_mode: forbidden: Remove thevendor/directory from your repository
Open Source
This policy is open source and available on GitHub. Contribute improvements, report issues, or fork it for your own use.
Common Use Cases
Explore how individual guardrails work with specific integrations.
Ready to Automate Your Standards?
See how Lunar can turn your engineering wiki, compliance docs, or postmortem action items into automated guardrails with our 100+ built-in guardrails.