When I read a copy of the docker/distribution source code, I find there are variables declared which make me quite confused. The code is:
var _ FileInfo = FileInfoInternal{}
var _ FileInfo = &FileInfoInternal{}
I don't know what the declare mean, and hope to get some help.
From the FAQ:
In this case the blank identifier _ stands for the variable name which is not needed here (and thus prevents a "declared but not used" error).
And more general from the spec:
By testing both
FileInfoInternal{}
and&FileInfoInternal{}
you check if the interface is implemented with a value receiver. A value receiver will accept both a value and a pointer whereas the pointer receiver will only work with a pointer and the first assignment by value will fail.The second test with
&FileInfoInternal{}
is not actually needed (as confirmed by the author in the comments) since the first test will pass with a value receiver and fail with a pointer received. Thus the second test is redundant.This is an excellent article that explains the difference between value and pointer receivers and how they are used very well.
FileInfo
is an interface and the code checks whetherFileInfoInternal
implements this interface.