使用go mod,注意你所使用的go版本应为11以上。
go mod的思想类似于maven:拥抱本地库,使用go mod后,你会发现go modules 下载的包在 GOPATH/pkg/mod。具体使用可查看下面地址。
官网
https://github.com/golang/go/wiki/Modules
不同管理工具对比
https://github.com/golang/go/wiki/PackageManagementTools
go mod的使用
https://studygolang.com/articles/19010
https://ieevee.com/tech/2018/08/28/go-modules.html?utm_source=tuicool&utm_medium=referral
有些包无法获取,比如:golang.org,google.golang.org,cloud.google.com等,可采用GOPROXY,需要go版本为13以上
https://goproxy.io/
报错并解决
1.module declares its path as: oauth2,but was required as: github.com/llaoj/oauth2
场景:clone 代码(https://github.com/llaoj/oauth2.git)到本地,运行后报错
解决:删除go.mod,go.sum,重新初始化go mod init github.com/llaoj/oauth2,注意观察go.mod的module