Awesome Go

gofindimpl

CategoryGo Tools
SubcategoryGo Tools
Stars3

Find all structs that implement a given Go interface across a codebase

About gofindimpl

gofindimpl 🔍

Go Reference CI coverage version license

Hunt down Go interface implementations like a bloodhound with trust issues.

Tired of grep-ing through thousands of lines trying to figure out which structs actually implement that damn interface? This tool does the heavy lifting so you don't have to suffer through another existential crisis at 3am.

Installation

go install github.com/psyb0t/gofindimpl@latest

Or skip the install and run it directly:

go run github.com/psyb0t/gofindimpl@latest \
  -interface ./path/to/file.go:InterfaceName \
  -dir ./search/directory

Needs Go 1.26 or newer.

Usage

Run it from your module root, the directory with go.mod in it. Not some anarchist directory, it checks.

gofindimpl \
  -interface ./internal/app/server.go:Server \
  -dir ./internal/pkg/

You get JSON on stdout, because XML is for people who hate themselves:

[
  {
    "package": "impl",
    "struct": "WebServer",
    "packagePath": "github.com/yourproject/internal/pkg/impl"
  },
  {
    "package": "mock",
    "struct": "MockServer",
    "packagePath": "github.com/yourproject/internal/pkg/mock"
  }
]

Add -debug if you're a masochist and want to watch every directory get walked. Logs go to stderr, so the JSON stays clean enough to pipe into jq. Every flag, the output fields and the exit codes are on Command line.

How it works

It parses the interface file, walks -dir, type-checks every package it finds with Go's own type checker and a fake importer, and reports each struct whose value or pointer method set has every method name the interface declares. Test files, vendor, node_modules and dot-directories don't get analyzed.

Read the fine print before you trust the output. It compares method names, not signatures, it ignores embedded interfaces, it can't see methods promoted from another package, and with the default -dir . it skips the package in the module root itself. How it works has all of it.

Documentation

The full docs live at psyb0t.github.io/gofindimpl.

PageWhat's in it
Command lineFlags, the file.go:InterfaceName spec, JSON output, logs and exit codes
How it worksWhat gets scanned, what counts as an implementation, and the limits
TroubleshootingEvery error message, why a search comes back empty, and why it finds too much
DevelopmentMake targets, tests, the coverage gate, CI and releases

Sponsor

License

MIT, because pkg.go.dev are corporate fuckers who won't index WTFPL packages.

Frequently Asked Questions

What is gofindimpl?

gofindimpl is a Go Tools library for the Go programming language. Find all structs that implement a given Go interface across a codebase

How do I install gofindimpl?

Install gofindimpl with the Go module system using `go get psyb0t/gofindimpl`. Check the repository for the current installation instructions.

What category does gofindimpl belong to?

gofindimpl is listed under Go Tools, specifically Go Tools.

← Back to Go Tools