Version: v0.0.0-...-df1b20f Latest Latest

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

Go to latest
Published: Sep 2, 2018 License: Apache-2.0, BSD-3-Clause Imports: 15 Imported by: 18



GoDoc Build Status

A linter that suggests interface types. In other words, it warns about the usage of types that are more specific than necessary.

go get -u
func ProcessInput(f *os.File) error {
        b, err := ioutil.ReadAll(f)
        if err != nil {
                return err
        return processBytes(b)
$ interfacer $(go list ./... | grep -v /vendor/)
foo.go:10:19: f can be io.Reader
Basic idea

This tool inspects the parameters of your functions to see if they fit an interface type that is less specific than the current type.

The example above illustrates this point. Overly specific interfaces also trigger a warning - if f were an io.ReadCloser, the same message would appear.

It suggests interface types defined both in the func's package and the package's imports (two levels; direct imports and their direct imports).

False positives

To avoid false positives, it never does any suggestions on functions that may be implementing an interface method or a named function type.

It also skips parameters passed by value (excluding pointers and interfaces) on unexported functions, since that would introduce extra allocations where they are usually not worth the tradeoff.

Suppressing warnings

If a suggestion is technically correct but doesn't make sense, you can still suppress the warning by mentioning the type in the function name:

func ProcessInputFile(f *os.File) error {
	// use as an io.Reader




This section is empty.


This section is empty.


func CheckArgs

func CheckArgs(args []string) ([]string, error)

CheckArgs checks the packages specified by their import paths in args.

func Interfacer

func Interfacer(packagesPath map[string]string) []string


type Checker

type Checker struct {
	// contains filtered or unexported fields

func (*Checker) Check

func (c *Checker) Check() ([]lint.Issue, error)

func (*Checker) Program

func (c *Checker) Program(lprog *loader.Program)

func (*Checker) ProgramSSA

func (c *Checker) ProgramSSA(prog *ssa.Program)

func (*Checker) Visit

func (c *Checker) Visit(node ast.Node) ast.Visitor

type Issue

type Issue struct {
	// contains filtered or unexported fields

func (Issue) Message

func (i Issue) Message() string

func (Issue) Pos

func (i Issue) Pos() token.Pos

Jump to

Keyboard shortcuts

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