Skip to content

Go

Go is a statically typed, compiled language known for simplicity and excellent tooling. LumenFlow’s go preset provides sensible defaults for Go projects.

  1. Add preset to your configuration

    # .lumenflow.config.yaml
    version: '2.0'
    
    gates:
      execution:
        preset: 'go'
  2. Run gates

    pnpm gates
    # Or with the GitHub Action
  3. Done!

    The preset runs gofmt, golangci-lint, go vet, and go test automatically.

The go preset uses these commands:

GateCommandDescription
Formatgofmt -l .Check formatting (list unformatted files)
Lintgolangci-lint runRun comprehensive linter suite
Typecheckgo vet ./...Report likely mistakes in code
Testgo test ./...Run all tests

Override specific commands while keeping preset defaults for others:

gates:
  execution:
    preset: 'go'
    # Override format check to fail on unformatted files
    format: 'test -z "$(gofmt -l .)"'
    # Add race detection to tests
    test: 'go test -race -v ./...'

For complete control, omit the preset and define all commands:

gates:
  execution:
    format: 'test -z "$(gofmt -l .)"'
    lint: 'golangci-lint run --timeout 5m'
    typecheck: 'go vet ./...'
    test: 'go test -race -coverprofile=coverage.out ./...'

The recommended linting tool for Go projects:

gates:
  execution:
    preset: 'go'
    lint: 'golangci-lint run --timeout 5m'

Configure golangci-lint with .golangci.yml:

# .golangci.yml
linters:
  enable:
    - gofmt
    - govet
    - errcheck
    - staticcheck
    - unused
    - gosimple
    - ineffassign

run:
  timeout: 5m

Add test coverage reporting:

gates:
  execution:
    preset: 'go'
    test: 'go test -coverprofile=coverage.out ./... && go tool cover -func=coverage.out'

Include build in your gates:

gates:
  execution:
    preset: 'go'
    lint: 'go build ./... && golangci-lint run'
name: LumenFlow Gates

on:
  pull_request:
    branches: [main]
  push:
    branches: [main]

jobs:
  gates:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Setup Go
        uses: actions/setup-go@v5
        with:
          go-version: '1.22'

      - name: Install golangci-lint
        run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest

      - name: Run LumenFlow Gates
        uses: hellmai/lumenflow-gates@v1
        with:
          token: ${{ secrets.LUMENFLOW_TOKEN }}

LumenFlow works well with standard Go module layouts:

myproject/
├── .lumenflow.config.yaml
├── go.mod
├── go.sum
├── cmd/
│   └── myapp/
│       └── main.go
├── internal/
│   ├── domain/
│   │   └── domain.go
│   └── handler/
│       └── handler.go
└── pkg/
    └── client/
        └── client.go

For Go monorepos or workspaces:

gates:
  execution:
    preset: 'go'
    # Run from repo root, tests all modules
    test: 'go test ./...'
    lint: 'golangci-lint run ./...'

Or run gates per-module with the GitHub Action:

jobs:
  api:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-go@v5
        with:
          go-version: '1.22'
      - uses: hellmai/lumenflow-gates@v1
        with:
          token: ${{ secrets.LUMENFLOW_TOKEN }}
          working-directory: services/api

The default gofmt -l . lists unformatted files but returns exit code 0. Use:

format: 'test -z "$(gofmt -l .)"'

This fails if any files need formatting.

For large projects, increase the timeout:

lint: 'golangci-lint run --timeout 10m'

If using vendor/, exclude it from checks:

format: 'test -z "$(gofmt -l $(find . -name "*.go" -not -path "./vendor/*"))"'
lint: 'golangci-lint run --skip-dirs vendor'