pointerinterface
pointerinterface
is a linter that warns about the usage of new type declarations
with pointer to interface values.
Usage
Installation:
go install code.larus.se/lmas/pointerinterface@latest
Running:
pointerinterface ./...
Testing:
go test -cover ./...
Explanation
You almost never need a pointer to an interface.
An interface is represented by a two-word pair, containing:
- A pointer to type-specific information (the "type")
- Another pointer to the associated data (the "data", always as a pointer despite the type of data)
Thus using a pointer to interface
is redundant (a pointer to pointers) and
makes it harder to use practically.
A demonstration of this issue (and a better alternative) can be found inside testdata/
.
A related question can be found at Stack Overflow.