如何安装govendor并打开项目

安装govendor

参考Go Dependencies via govendor
English

使用go 1.18,在任意目录执行go install安装govendor

go install github.com/kardianos/govendor@latest

将项目放置到$GOPATH/src1,在项目内列出依赖列表

govendor list

可以看到该项目内的各种依赖

...
 l  moby/volume
 l  moby/volume/drivers
 l  moby/volume/local
 l  moby/volume/mounts
 l  moby/volume/service
 l  moby/volume/service/opts
 l  moby/volume/testutils
  m appengine
  m appengine_internal
  m appengine_internal/base

之后对每个没下载的依赖执行fetch即可:

govendor fetch github.com/docker/docker/pkg/reexec
govendor fetch github.com/docker/docker/rootless
...

不过用fetch的做法有点低效,笔者还没找到其他高效做法

踩坑

下载govendor失败

a connection attempt failed because the connected party did not properly respond after period of tim
GO A connection attempt failed because the connected party did not properly respond after a period…

如果go install下载失败,需要修改go的代理为国内镜像

go env -w GOPROXY=https://goproxy.cn

govendor路径错误

govendor error package not a go package or not in gopath

你的项目没有放置在$GOPATH/src

首先执行go env GOPATH查看路径,如果是不符合预期的,就参考windows11 如何修改环境变量,修改GOPATH系统变量。

删除govendor依赖

使用govendor fetch github.com/spf13/cobra来下载依赖,并到$GOPATH/.cache下删除依赖。

拉取不到指定分支

执行了govendor fetch命令后, 报错如下

D:\codes\src\moby>govendor fetch github.com/spf13/cobra
# cd D:\codes\.cache\govendor\github.com\spf13\cobra; git reset --hard origin/master
fatal: ambiguous argument 'origin/master': unknown revision or path not in the working tree
.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
Error: failed to sync to latest revision exit status 128
Failed to fetch package "github.com/spf13/cobra"

可以看到,govendor尝试执行git reset --hard origin/master,但找不到这个分支,因为原仓库本来就没这个分支


所以改为运行后,执行成功

govendor fetch github.com/spf13/cobra@main

  1. 参考Go Vendoring Beginner Tutorial的相关说明,提到Go to your project directory (it must be in the GOPATH src)可知,项目必须在GOPATH的src目录下。 ↩︎

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值