Hamburger Cross Icon
Go Collector - Lunar Collector

Go Collector

Collector Stable LanguagesBuild

Analyze Go projects to collect module info, dependencies, test coverage, and golangci-lint results. Enforce Go-specific engineering standards.

Add 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.

Collector ci-before-command

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.

go ci go version ci commands build tracking
Book a demo
Collector ci-before-command

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.

go test test scope recursive tests package tests
Book a demo
Collector ci-after-command

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.

code coverage go test coverage coverprofile coverage metrics
Book a demo
Collector code

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.

go modules go.mod project structure go workspace
Book a demo
Collector code

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.

golangci-lint go linting static analysis code quality
Book a demo
Collector code

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.

go dependencies go modules dependency graph supply chain
Book a demo

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
1
Collectors Gather Data This Integration
Triggered by code changes or CI pipelines, collectors extract metadata from config files, tool outputs, test results, and scans
2
{ } Centralized as JSON
All data merged into each component's unified metadata document
3
Guardrails Enforce Standards
Real-time feedback in PRs and AI workflows

Example Collected Data

This collector writes structured metadata to the Component JSON. Here's an example of the data it produces:

{ } component.json Component JSON
{
  "lang": {
    "go": {
      "module": "github.com/acme/myproject",
      "version": "1.21",
      "build_systems": ["go"],
      "go_mod_exists": true,
      "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 GitHub

Go 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.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.

View Repository

Common Use Cases

Explore guardrails that use data from Go Collector.

+
Min Versions + Go Collector Ensures dependencies meet minimum safe version requirements. Validates that...
+
Go Mod Exists + Go Collector Ensures the project has a go.mod file for module management. Required for all Go...
+
Go Sum Exists + Go Collector Ensures the project has a go.sum file for dependency verification. Required for...
+
Min Go Version + Go Collector Ensures the project uses at least the minimum required Go version. Helps...
+
Min Go Version Cicd + Go Collector Ensures the Go version used in CI/CD commands meets the minimum required...
+
Tests Recursive + Go Collector Ensures tests run recursively (./...) to cover all packages. Prevents...
+
Vendoring + Go Collector Enforces vendoring policy - can require vendor directory exists or forbid it,...
+
Ran + Go Collector Ensures linting was executed for the specified language. Fails if no lint data...
+
Max Warnings + Go Collector Ensures lint warnings are at or below the maximum allowed threshold. Validates...
+
Executed + Go Collector Ensures tests were executed in CI. Fails if no test execution data is found.
+
Passing + Go Collector Ensures all tests pass. Fails if test pass/fail data is not available.
+
Coverage Collected + Go Collector Ensures coverage data is being collected in CI. Fails if no coverage data is...
+
Coverage Reported + Go Collector Ensures coverage percentage is being reported. Fails if coverage runs but...
+
Min Coverage + Go Collector Enforces a minimum code coverage threshold (default 80%). Fails if coverage data...

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.

Works with any process
check Infrastructure conventions
check Post-mortem action items
check Security & compliance policies
check Testing & quality requirements
Automate Now
Turn any process doc into guardrails
Book a Demo