Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use goconst to find repeated string literals in Go code and review them as candidates for constants. Install it with Go, run it across your project, then decide whether each repeated value represents one shared concept worth naming. A match is a prompt for review—not an instruction to extract a constant.

Install goconst and scan a Go project

The documented quick start installs the command with Go and scans the current project’s packages:

go install github.com/jgautheron/goconst/cmd/goconst@latest
goconst ./...

The first command installs the latest available version of goconst; the second passes the current directory and its subdirectories to the analyzer. You can also pass specific directories to scan. For the installed version’s available options, run goconst -h or goconst --help; flags may change between releases.

What goconst reports—and what counts as a match

goconst detects repeated string literals and can optionally inspect numeric literals. It compares complete, unquoted literal values exactly: two occurrences of "request failed" can match, but "request failed: " and "request failed: %s" are different values. A shared substring inside distinct longer strings is not enough to produce a match.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

By default, constant declarations are skipped. Use -match-constant to check literals against existing constants, or -find-duplicates to find constants that have identical values. The -min-length threshold counts string runes, not bytes, so multibyte Unicode characters count as characters.

Adjust the scan to fit the codebase

goconst’s CLI options let you control which findings appear and how results are presented. The documented minimums are two occurrences for -min-occurrences and three characters for -min-length.

Need Relevant option
Require more repeats or change the minimum string length -min-occurrences, -min-length
Exclude matching files or strings, or skip tests -ignore, -ignore-strings, -ignore-tests (documented default: true)
Include literals compared with constants or find duplicate constants -match-constant, -find-duplicates
Evaluate constant expressions or ignore selected calls and contexts -eval-const-expr, -ignore-calls, -ignore-composite-literals, -ignore-map-keys
Check numeric literals and set a numeric range -numbers, -min, -max
Choose output format, set a failing exit status, or group findings -output, -set-exit-status, -grouped

For example, to require at least three occurrences, scan for numeric literals, and write JSON output, consult the installed version’s help for the exact option syntax and supported output values. Defaults and available flags can differ by release, so use that help text when adding a command to a project script or CI job.

Choose standalone goconst or golangci-lint

There are two documented ways to run this check: invoke the standalone goconst command, or configure goconst through golangci-lint. Choose based on where your team already runs and maintains checks, and whether the integration exposes the thresholds and exclusions your project needs.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The golangci-lint reference documents goconst settings for minimum length and occurrence count, matching constants, duplicate numbers, numeric ranges, ignored calls, and excluded contexts. Check the reference for the release you use before relying on a particular setting. Neither tool’s documentation establishes that one route is faster or produces fewer false positives; those outcomes depend on the project and configuration.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Review each finding before extracting a constant

Repeated text can represent one shared concept, but identical spelling alone does not establish that it should have one owner or one name. Before changing code, consider whether the occurrences mean the same thing, whether a single edit should intentionally update all of them, and whether the proposed constant’s name would clarify its role. Keep separate literals separate when they happen to have the same value but represent different concepts.

That review matters because a shared constant changes the relationship between call sites: changing its value affects every use. Use goconst to locate candidates efficiently, then let code meaning and maintainability—not the match alone—decide whether to refactor.

Quick Recap

SaleBestseller No. 5
Go Programming Language Design With Go Logo Go Developers T-Shirt
Go Programming Language Design With Go Logo Go Developers T-Shirt
Go Programming Language Developers and Programmers will love this design.; Go Logo for software engineers who like to work in Golang Programming Language.
$16.99
Best Value
Sale
Go Programming Language Design With Go Logo Go Developers T-Shirt
  • Go Programming Language Developers and Programmers will love this design.
  • Go Logo for software engineers who like to work in Golang Programming Language.
  • Lightweight, Classic fit, Double-needle sleeve and bottom hem

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.