解决golang依赖库被删库问题

调用的开源库引用了github个人仓库,如果作者删除了仓库或者改成私人仓库,那么go mod tidy就会失败
以github.com/mitchellh/osext为例,作者因为某些原因删除了仓库,并给出了替代的官方仓库github.com/kardianos/osext

  • 使用replace命令
    go mod edit -replace [old git package]@[version]=[new git package]@[version]
  • go.mod文件中会新增一行
    replace github.com/mitchellh/osext v0.0.0-20151018003038-5e2d6d41470f => github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
  • 此时使用 go mod tidy会报错
    go: github.com/kardianos/osext@v0.0.0-20190222173326-2bc1f35cddc0 used for two different module paths (github.com/kardianos/osext and github.com/mitchellh/osext)
  • 增加一行去掉被替换仓库
    exclude github.com/mitchellh/osext v0.0.0-20151018003038-5e2d6d41470f
posted on 2024-02-06 10:29  umichan  阅读(668)  评论(0)    收藏  举报