# Go

---

## Overview

Publish Go modules to your team's registry and pull dependencies from proxy.golang.org, all cached and managed through Fly.

Go modules is the dependency management system for Go projects. JFrog Fly proxies Go modules from [proxy.golang.org](https://proxy.golang.org) (the official Go module mirror) and hosts your team's private modules. By configuring Fly, all your dependencies are cached and managed through Fly, providing faster downloads, unified dependency management, and a private registry for your own modules.

---

## Supported Clients

JFrog Fly supports Go modules with:

- **Go CLI** (`go get`, `go mod download`) - The standard Go toolchain for managing dependencies

---

## Download Module

### With Fly App

Activate Go in your Fly App to configure your `GOPROXY` to use Fly. All modules from proxy.golang.org will be cached and managed through Fly:

```bash
go get <module-path>
```

Or download all dependencies:

```bash
go mod download
```

### Manual Configuration

**1. Generate an access token** in Fly Token Management

**2. Configure GOPROXY** to route through Fly:

```bash
go env -w GOPROXY=https://<your-fly-username>:<your-fly-token>@<your-fly-subdomain>.jfrog.io/artifactory/api/go/go,direct
```

> [!TIP]
> The `,direct` fallback ensures that if a module is not found in Fly, Go will attempt to fetch it directly from the source. This is the recommended configuration.

**3. Download module:**

```bash
go get <module-path>
```

All modules will be fetched from proxy.golang.org through Fly and cached for future use.

---

## Download Modules with CI

To download Go modules with CI, update your GitHub Actions workflow to include the Fly action.

Simply ask your coding agent: **"Configure my workflows with Fly"** and Fly MCP will configure your GitHub Actions workflow yml file, as follows:

**1. Add permissions** (top level, after `on:`):
```yaml
permissions:
  contents: read
  id-token: write
```

**2. Add Fly Action** (after `actions/setup-go`, before go commands):
```yaml
- uses: jfrog/fly-action@v1              # Setup Fly package managers
```

### GitHub Action Example

```yaml
name: Build Go Application

on:
  push:
    branches: [main]

permissions:
  contents: read
  id-token: write

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v6

      - uses: actions/setup-go@v6
        with:
          go-version: '1.26'

      - uses: jfrog/fly-action@v1              # Setup Fly package managers

      - run: go mod download                   # Modules from Fly registry

      - run: go build -v ./...

      - run: go test -v ./...
```

---

## Publish Module with CI

To publish Go modules from CI, add the `jfrog/fly-action/go-publish` step to your GitHub Actions workflow.

**1. Add permissions** (top level, after `on:`):
```yaml
permissions:
  contents: read
  id-token: write
```

**2. Add Fly Action and publish step** (in your job's `steps:`):
```yaml
- uses: jfrog/fly-action@v1              # Setup Fly package managers

- uses: jfrog/fly-action/go-publish@v1   # Publish Go module
```

The action auto-detects the module path from `go.mod` and the version from git tags. To override:

```yaml
- uses: jfrog/fly-action/go-publish@v1   # Publish Go module
  with:
    path: ./path/to/module
    version: v1.2.0
```

| Input | Required | Description |
|-------|----------|-------------|
| `path` | No | Path to the Go module directory (defaults to repo root) |
| `version` | No | Explicit module version (auto-detected from git tags if omitted) |

### GitHub Action Example

```yaml
name: Publish Go Module

on:
  push:
    tags: ['v*']

permissions:
  contents: read
  id-token: write

jobs:
  publish:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v6
        with:
          fetch-depth: 0

      - uses: actions/setup-go@v6
        with:
          go-version: '1.26'

      - uses: jfrog/fly-action@v1              # Setup Fly package managers

      - uses: jfrog/fly-action/go-publish@v1   # Publish Go module
```

> [!TIP]
> Use `fetch-depth: 0` in `actions/checkout` so the action can read git tags for automatic version detection.

---

*Back to [Package Managers →](../)*
