1 首先在原有项目里直接删除 vendor 这个文件夹
2 go mod init
3 go mod tidy
等待下载完毕
4 运行main.go文件会发现 go.mod里面文件都加载完毕
如果出现报错:
google.golang.org/grpc/naming: looping trying to add package
是因为grpc版本不一样,自动引入的是40版本
google.golang.org/grpc v1.40.0 // indirect
我们需要修改为: google.golang.org/grpc v1.37.0
然后替换掉:
replace google.golang.org/grpc v1.37.0 => google.golang.org/grpc v1.26.0
require (
github.com/chanxuehong/internal v0.0.0-20180430074813-85d6017afbc4 // indirect
github.com/chanxuehong/rand v0.0.0-20201110082127-2f19a1bdd973 // indirect
github.com/chanxuehong/uuid v0.0.0-20180430073920-75ab5e2d8298 // indirect
github.com/coreos/etcd v3.3.25+incompatible // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
github.com/garyburd/redigo v1.6.2 // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/goinggo/mapstructure v0.0.0-20140717182941-194205d9b4a9 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/honsty/cryptos v0.0.0-20180710074443-22ca856b9265 // indirect
github.com/jinzhu/gorm v1.9.16 // indirect
github.com/jtolds/gls v4.20.0+incompatible // indirect
github.com/labstack/echo v3.3.10+incompatible // indirect
github.com/labstack/gommon v0.3.0 // indirect
go.uber.org/automaxprocs v1.4.0 // indirect
go.uber.org/zap v1.19.1 // indirect
golang.org/x/net v0.0.0-20210924054057-cf34111cab4d // indirect
google.golang.org/grpc v1.37.0 // indirect
)