Closed avidal closed 7 years ago
The search path for dependencies mirrors that of the import
statement where it makes sense. The Importer
is leveraged by the Parser
such that it will scan the vendor directory first when trying to find a reference that exists outside of the top level package being rendered.
Specifically, when the parser encounters a type that does not exist in the top level package being scanned then it will look in this order:
Something else noteworthy, the search process will only leverage the vendor directory of the top level, target package being scanned. It won't recursively use the vendor directory of dependencies. So, for example, if the imported type is not found in the local vendor then it will try to find it in the GOPATH. If it finds the package in GOPATH but needs to resolve a type from yet another package it will, again, first look in the original vendor directory first. Basically, whatever is placed in the local vendor is preferred over anything else. Otherwise, the GOPATH is leveraged but never a nested vendor directory. As a final fallback the search will look in GOROOT.
Thanks. It may be worth putting this in the README as one of the differences with mockgen. It's enough for me to try it out at least.
The importer code seems to indicate that you can specify a
from
argument which is a vendor tree, but the parser code only seems to call the importer withfrom
set to "". Am I missing something?I ask because one of the problems with mockgen is that it only scans packages from the $GOPATH, and so it becomes difficult to ensure you are generating mocks for the same version of your dependency, does this tool avoid that problem?