# What Is the Default Target Go Version for the go-modern-guidelines CLI?

> Discover the default target Go version for the go-modern-guidelines CLI. Learn how it uses your local Go toolchain version when no flags are specified.

- Repository: [JetBrains/go-modern-guidelines](https://github.com/jetbrains/go-modern-guidelines)
- Tags: faq
- Published: 2026-08-30

---

**When executed without explicit version flags, the go-modern-guidelines CLI defaults to the local Go toolchain version obtained from `go env GOVERSION`.**

The go-modern-guidelines CLI analyzes Go code against specific language versions to enforce modern best practices. When you run the tool without specifying a target version, it automatically detects the Go version installed on your local machine. This default detection mechanism ensures that the CLI aligns with your current development environment without requiring manual configuration.

## How the CLI Determines the Default Go Version

The resolution logic resides in the `goversion` package and follows a clear fallback chain. When both the `--go-version` flag and a module file path are omitted, the CLI invokes the `goversion.Resolve` function with empty parameters.

In [`internal/goversion/goversion.go`](https://github.com/JetBrains/go-modern-guidelines/blob/main/internal/goversion/goversion.go) (lines 62-67), the `Resolve` function checks if both `filePath` and `goVersion` arguments are empty strings. When this condition is met, it immediately delegates to `resolveGoToolVersion` to query the local Go installation.

### The Local Toolchain Query

The `resolveGoToolVersion` function, defined at lines 63-71 in [`internal/goversion/goversion.go`](https://github.com/JetBrains/go-modern-guidelines/blob/main/internal/goversion/goversion.go), executes the following shell command to retrieve the host's Go version:

```bash
go env GOVERSION

```

This command returns the version string of the Go binary currently installed on the system (for example, `go1.22.5` or `devel` for development builds). The function then normalizes this output to produce a standardized version identifier used throughout the analysis.

### CLI Entry Point

The command-line interface parses user input in [`internal/cli/cli.go`](https://github.com/JetBrains/go-modern-guidelines/blob/main/internal/cli/cli.go) (lines 79-84). When no `--go-version` flag is provided and no path to a `go.mod` or `go.work` file is specified, the CLI passes empty strings to the resolution function, triggering the local toolchain detection path.

## Code Implementation Details

The following simplified Go code illustrates how the default version resolution flows through the system:

```go
// Resolution triggered from CLI parsing
targetVersion, err := goversion.Resolve(
    "",               // filePath: not supplied
    "",               // goVersion: no --go-version flag
    guidelines.LatestKnownVersion(), // fallback reference
)

// Inside goversion.Resolve (lines 62-67):
if filePath == "" && goVersion == "" {
    return resolveGoToolVersion()
}

// Inside resolveGoToolVersion (lines 63-71):
output, err := exec.Command("go", "env", "GOVERSION").Output()
normalized, err := normalizeGoVersion(string(output), develVersion)
return normalized, nil

```

In this flow, `targetVersion` ultimately contains the normalized version string from your local Go installation (e.g., `"1.22"`), which the CLI then uses to filter and apply modern Go guidelines.

## Version Resolution Hierarchy

The CLI evaluates the target version in the following priority order:

1. **Explicit `--go-version` flag** — Uses the version string provided by the user
2. **Module file detection** — If a `go.mod` or `go.work` path is provided, extracts the declared version
3. **Local toolchain** — Executes `go env GOVERSION` to detect the host's installed Go version

Only when options 1 and 2 are absent does the system fall back to option 3, the local toolchain query.

## Summary

- **The default target Go version** for go-modern-guidelines is the version returned by `go env GOVERSION` on the host machine.
- **Resolution occurs** in [`internal/goversion/goversion.go`](https://github.com/JetBrains/go-modern-guidelines/blob/main/internal/goversion/goversion.go) through the `goversion.Resolve` function when both file paths and version flags are omitted.
- **The specific function** `resolveGoToolVersion` (lines 63-71) executes the toolchain query and normalizes the result.
- **CLI parsing** in [`internal/cli/cli.go`](https://github.com/JetBrains/go-modern-guidelines/blob/main/internal/cli/cli.go) (lines 79-84) initiates this resolution when no explicit version configuration is present.
- **Normalization** handles various version string formats, including development builds.

## Frequently Asked Questions

### How does go-modern-guidelines determine the default Go version?

When no version is specified via flags or module files, the CLI executes `go env GOVERSION` through the `resolveGoToolVersion` function in [`internal/goversion/goversion.go`](https://github.com/JetBrains/go-modern-guidelines/blob/main/internal/goversion/goversion.go). This retrieves and normalizes the version string of the locally installed Go toolchain, using it as the analysis target.

### What happens if I don't specify the --go-version flag?

If you omit the `--go-version` flag and don't provide a path to a `go.mod` file, the CLI automatically detects your local Go version. The `goversion.Resolve` function detects the empty parameters and calls `resolveGoToolVersion`, which queries your system's Go installation via the `go env` command.

### Can I override the default target version?

Yes, you can override the automatic detection by either passing the `--go-version` flag with a specific version string or by providing the path to a `go.mod` or `go.work` file. When either option is present, the CLI uses that explicit version instead of querying the local toolchain.

### What Go version does the CLI use if it cannot detect the local toolchain?

The analysis indicates that `guidelines.LatestKnownVersion()` serves as a fallback reference passed to the resolution function, though the primary default mechanism relies on `go env GOVERSION`. If the local toolchain query fails, the system has access to this latest known version constant as a reference point, though the specific error handling behavior depends on the implementation details in [`internal/goversion/goversion.go`](https://github.com/JetBrains/go-modern-guidelines/blob/main/internal/goversion/goversion.go).