Go Module模式下导入外部包报错的问题
希望大家在看这个文章之前简单了解 Module模式. 我本人在学习开发一个Demo的过程中需要用Module模式,然后就发现自己在循规蹈矩按照指示
go get github.com/jmoiron/sqlx
(使用jmoiron/sqlx), 自己的IDE(Goland)依然会报错:
去查询一下其他人的方法,但并没有针对我Module模式解决问题(大部分人是说自己在Vendor模式下的报错问题。)。在我打开官方文档的时候,看到:
The “module path” is the import path prefix corresponding to the module root.The go.mod file defines the module path and lists the specific versions of other modules that should be used when resolving imports during a build,by giving their module paths and versions.
后来明白,自己Module模式,应该跟go.mod有关,并且注意到IDE有个报错的解决办法:
sync dependencies of xxx
,然后发现自己的go.mod文件同样多了:
目前对Module模式还在理解当中,但是也算自己独立解决了一个问题。