Go Collector
Analyze Go projects to collect module info, dependencies, test coverage, and golangci-lint results. Enforce Go-specific engineering standards.
golang to your lunar-config.yml:uses: github://earthly/lunar-lib/collectors/golang@v1.0.0
What This Integration Collects
This integration includes 6 collectors that gather metadata from your systems.
cicd
Records every Go command executed in CI pipelines along with the Go version. Writes command strings and version info to .lang.go.cicd for audit trails and build reproducibility analysis.
.*\bgo\b .*
test-scope
Determines whether go test runs recursively (./...) or targets specific packages. Writes scope to .lang.go.tests.scope as "recursive" or "package" to verify comprehensive test execution in CI.
.*\bgo\b test.*
test-coverage
Extracts coverage percentage from go test -coverprofile output after tests complete. Parses the coverage profile file, runs go tool cover -func to calculate total percentage, and writes results to .lang.go.tests.coverage including the raw profile.
.*\bgo\b test.*-coverprofile.*
project
Analyzes Go project structure by detecting go.mod, go.sum, vendor directory, and goreleaser configuration. Extracts the module path and Go version from go.mod using go list. Writes project metadata to .lang.go with build system info.
golangci-lint
Runs golangci-lint with JSON output and collects structured lint warnings. Parses each issue into file, line, column, message, and linter name. Writes normalized warnings to .lang.go.lint and raw output to .lang.go.native.golangci_lint.
dependencies
Extracts direct and transitive dependencies from go.mod using go list -m -json all. Captures module path, version, and whether each dependency is indirect. Also records replace directives. Writes dependency graph to .lang.go.dependencies.
How Collectors Fit into Lunar
Lunar watches your code and CI/CD systems to collect SDLC data from config files, test results, IaC, deployment configurations, security scans, and more.
Collectors are the automatic data-gathering layer. They extract structured metadata from your repositories and pipelines, feeding it into Lunar's centralized database where guardrails evaluate it to enforce your engineering standards.
Learn How Lunar Works →Example Collected Data
This collector writes structured metadata to the Component JSON. Here's an example of the data it produces:
{
"lang": {
"go": {
"module": "github.com/acme/myproject",
"version": "1.21",
"build_systems": ["go"],
"native": {
"go_mod": { "exists": true, "version": "1.21" },
"go_sum": { "exists": true },
"vendor": { "exists": false },
"goreleaser": { "exists": true },
"golangci_lint": {
"passed": false,
"config_exists": true,
"exit_code": 1,
"output": "main.go:42:5: unused variable 'x' (unused)"
}
},
"source": { "tool": "go", "integration": "code" },
"cicd": {
"cmds": [{ "cmd": "go test ./...", "version": "1.21.5" }],
"source": { "tool": "go", "integration": "ci" }
},
"tests": {
"scope": "recursive",
"coverage": {
"percentage": 78.5,
"profile_path": "coverage.out",
"source": { "tool": "go cover", "integration": "ci" }
}
},
"dependencies": {
"direct": [
{ "path": "github.com/stretchr/testify", "version": "v1.8.4", "indirect": false }
],
"transitive": [
{ "path": "github.com/davecgh/go-spew", "version": "v1.1.1", "indirect": true }
],
"source": { "tool": "go mod", "integration": "code" }
},
"lint": {
"warnings": [
{ "file": "main.go", "line": 42, "column": 5, "message": "unused variable 'x'", "linter": "unused" }
],
"linters": ["golangci-lint"],
"source": { "tool": "golangci-lint", "integration": "code" }
}
}
}
}
Configuration
Configure this collector in your lunar-config.yml.
Inputs
| Input | Required | Default | Description |
|---|---|---|---|
lint_timeout
|
Optional |
10m
|
Timeout for golangci-lint (e.g., 5m, 10m) |
Documentation
View on GitHubGo Collector
Collects Go project information, CI/CD commands, test coverage, dependencies, and linting results.
Overview
This collector gathers metadata about Go projects including module information, dependency graphs, test coverage metrics, and golangci-lint results. It runs on both code changes (for static analysis) and CI hooks (to capture runtime metrics like test coverage).
Note: The CI-hook collectors (test-coverage, test-scope, cicd) don't run tests—they observe and collect data from go test commands that your CI pipeline already runs.
Collected Data
This collector writes to the following Component JSON paths:
| Path | Type | Description |
|---|---|---|
.lang.go |
object | Go project metadata (module, version, build systems) |
.lang.go.module |
string | Go module path (e.g., github.com/acme/myproject) |
.lang.go.cicd |
object | CI/CD command tracking with Go version |
.lang.go.tests |
object | Test scope and coverage information |
.lang.go.dependencies |
object | Direct and transitive dependencies |
.lang.go.lint |
object | Normalized lint warnings from golangci-lint |
.lang.go.native.golangci_lint |
object | Raw golangci-lint output and status |
Note: This collector writes Go-native coverage data to .lang.go.tests.coverage. For normalized cross-language coverage at .testing.coverage, use a dedicated coverage tool collector (CodeCov, Coveralls, etc.).
Collectors
This plugin provides the following collectors (use include to select a subset):
| Collector | Hook Type | Description |
|---|---|---|
project |
code | Collects Go project structure (go.mod, go.sum, vendor, goreleaser) |
dependencies |
code | Collects Go module dependency graph |
golangci-lint |
code | Runs golangci-lint and collects warnings |
cicd |
ci-before-command | Tracks Go commands run in CI with version info |
test-scope |
ci-before-command | Determines test scope (recursive vs package) |
test-coverage |
ci-after-command | Detects if go tests produced a coverage report and extracts results |
Installation
Add to your lunar-config.yml:
collectors:
- uses: github://earthly/lunar-lib/collectors/golang@v1.0.0
on: [go] # Or use domain: ["domain:your-domain"]
# include: [project, golangci-lint] # Only include specific subcollectors
# with:
# lint_timeout: "10m"
Open Source
This collector is open source and available on GitHub. Contribute improvements, report issues, or fork it for your own use.
Common Use Cases
Explore guardrails that use data from Go Collector.
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.