vendor目錄與import相對路徑的local包且該包import了vendor目錄的第三方庫時踩的坑
不知是不是go的bug。 我的GOPATH是F:\GoPath。 下載的第三方包gin庫在F:\GoPath\src\github.com\gin-gonic\gin。 我在F:\GoPath\src下又建了自己的工程目錄Test,即 F:\GoPath\src\Test。 在工程目錄裡有: main.go Handler\handler.go main.go程式碼:  handler\handler.go程式碼:  在F:\GoPath\src\Test執行命令列 go build -o main.exe main.o,成功。import的github.com\gin-gonic\gin包在F:\GoPath\src找到。 好了,在F:\GoPath\src\Test目錄裡建立vendor包,將F:\GoPath\src\github.com\gin-gonic\gin包拷貝到F:\GoPath\src\Test\vendor中(拷貝也可以用govendor命令操作),按官方對vendor目錄作用的解釋,專案裡import的github.com\gin-gonic\gin包先到vendor目錄裡找,沒有才到GOROOT和GOPATH環境變數目錄裡去找。事實上此時執行go build -o main.exe main.o,報錯:  我去ubuntu系統上試了一下,一樣的報錯。 找了很久原因,還不知為什麼,只是找到了解決辦法,修改main.go程式碼:  即將相對於main.go當前目錄的 import "./handler" 改成了 相對於 GOPATH的 import "Test/handler" ,執行go build -o main.exe main.o成功。