go语言第三方包依赖管理工具govendor,报错cannot find package “gopkg.in/go-playground/validator.v8”

问题

# go run main.go
                                           
vendor/github.com/gin-gonic/gin/binding/default_validator.go:11:2: cannot find package "gopkg.in/go-playground/validator.v8" in any of:
	/Users/jackyue/go/src/github.com/locutus666/mygin/vendor/gopkg.in/go-playground/validator.v8 (vendor tree)
	/usr/local/go/src/gopkg.in/go-playground/validator.v8 (from $GOROOT)
	/Users/jackyue/go/src/gopkg.in/go-playground/validator.v8 (from $GOPATH)
vendor/github.com/gin-gonic/gin/render/yaml.go:10:2: cannot find package "gopkg.in/yaml.v2" in any of:
	/Users/jackyue/go/src/github.com/locutus666/mygin/vendor/gopkg.in/yaml.v2 (vendor tree)
	/usr/local/go/src/gopkg.in/yaml.v2 (from $GOROOT)
	/Users/jackyue/go/src/gopkg.in/yaml.v2 (from $GOPATH)

解决

在mygin工程目录下的vendor文件夹中,go并没有找到gin框架所依赖的第三方包,我们只能单独想办法下载。
翻看vendor/vendor.json,我们可以知道在github下载到依赖。

比如,gopkg.in/go-playground/validator.v8 这个包,实际对应的就是 github.com/go-playground/validator 的v8分支,那么只要 git clone -b v8 https://github.com/go-playground/validator.git 就可以拉下来。重命名后,在mygin工程目录下的vendor文件夹中,按照 gopkg.in/go-playground/validator.v8 路径,放置第三方包。

gopkg.in/yaml.v2 依赖包也可以以类似方式处理。


版权声明:本文为yjk13703623757原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
THE END
< <上一篇
下一篇>>