ifgen

command module
v0.0.0-...-f3fdc62 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2025 License: MIT Imports: 23 Imported by: 0

README

ifgen: an interface generator that makes writing testable go fun

Ifgen generates go interfaces based on what you use.

To use ifgen in your project, firstly add it to the go.mod tools section.

tool (
	github.com/hpidcock/ifgen
)

Then in packages that need generated interfaces for foreign types, add a go generate comment similar to:

//go:generate go tool ifgen -pkg mypackage github.com/google/go-github/v66/github:IssuesService=>GithubIssuesService

In this example, mypackage will have a package scoped type GithubIssuesService. Ifgen creates two versions of the interface, one is called the "pure" interface, the other is the impure interface.

The impure interface can be used by your code editor for autocompletion. While the pure interface is generated to only have the methods required by your package.

To setup your code editor for use with ifgen, add the Go impure build tag.

.vscode/settings.json:

{
    "go.buildTags": "impure"
}

.zed/settings.json

{
  "lsp": {
    "gopls": {
      "initialization_options": {
        "buildFlags": ["-tags=impure"]
      }
    }
  }
}

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL