Hamburger Cross Icon
Go Mod Exists
+
Go Collector

Go Mod Exists + Go Collector

Guardrail Collector Stable Devex Build And Ci

Enforce Go Mod Exists using data collected by Go Collector. Automatically check devex build and ci standards on every PR.

Guardrail: Ensures the project has a go.mod file for module management. Required for all Go projects using modules.
Data Source: Analyze Go projects to collect module info, dependencies, test coverage, and golangci-lint results. Enforce Go-specific engineering standards.

How Go Collector Powers This Guardrail

The Go Collector gathers metadata from your languages, build systems. This data flows into Lunar's Component JSON, where the Go Mod Exists guardrail evaluates it against your standards.

When enabled, this check runs automatically on every PR and in AI coding workflows, providing real-time enforcement with actionable feedback.

1
Go Collector Gathers Data Collector
Extracts metadata from code, configs, and tool outputs
2
{ } Component JSON
Data centralized in structured format for evaluation
3
Go Mod Exists Checks Guardrail
Pass/fail result with actionable feedback in PRs

Quick Start Configuration

Add both the collector and policy to your lunar-config.yml to enable this guardrail.

📄 lunar-config.yml
# Step 1: Enable the Go Collector
collectors:
  - uses: github://earthly/lunar-lib/collectors/golang@v1.0.0
    # with: ...

# Step 2: Enable the Go Project Guardrails
policies:
  - uses: github://earthly/lunar-lib/policies/golang@v1.0.0
    include: [go-mod-exists]
    # with: ...

What Go Collector Collects

This collector gathers the following data that the Go Mod Exists guardrail evaluates.

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.

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.

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.

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.

Example Data Flow

Here's an example of the data that Go Collector writes to the Component JSON, which Go Mod Exists then evaluates.

{ } component.json From Go Collector
{
  "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 Options

Go Collector Inputs

Input Required Default Description
lint_timeout Optional 10m Timeout for golangci-lint (e.g., 5m, 10m)

Go Project Guardrails 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)

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