Golang has this nice vendoring feature where you could keep your import paths canonical while storing actual libraries in different places ($GOPATH and vendor). But while coding your way, you may have come across the dilemma where vendored libraries in different levels, even though being the same in actuality, are recognized as different packages by the compiler.
Say, you have a library called common, in which you imported and vendored in github.com/golang/mock. In your program prog you imported common, but also you imported and vendored in github.com/golang/mock. At this point if you go and build prog, bam, you'd get your compiler complaining about the two gomock being different packages.
The solution, long story short, is to flatten all vendored libraries into the topmost vendor folder. That is, removing vendors from common, and having github.com/golang/mock, as well as other vendors, both by common and prog, all in the vendor folder of prog.
Another similar example - https://github.com/mattfarina/golang-broken-vendor
To make things easier, this manner of practice have even got some tooling support:
https://stackoverflow.com/questions/38597046/how-to-handle-nested-vendor-directories-in-go-packages
https://github.com/kardianos/govendor/blob/master/doc/faq.md#q-how-do-i-prevent-vendor-source-from-being-checked-in
https://github.com/golang/dep/issues/985
Refer to the following discussions for more details:
https://groups.google.com/forum/#!msg/golang-nuts/AnMr9NL6dtc/UnyUUKcMCAAJ
https://www.reddit.com/r/golang/comments/4cptba/best_practice_for_vendoring_in_libraries/
没有评论:
发表评论