使用Go安装Levant遇consul/api模糊导入错误,求解决方法
解决
go install github.com/hashicorp/levant 的模糊导入错误 执行go install github.com/hashicorp/levant安装Levant时触发模糊导入错误,报错信息如下:
go install github.com/hashicorp/levant build github.com/hashicorp/levant: cannot load github.com/hashicorp/consul/api: ambiguous import: found github.com/hashicorp/consul/api in multiple modules: github.com/hashicorp/consul v0.0.0-20171026175957-610f3c86a089 (/root/go/pkg/mod/github.com/hashicorp/consul@v0.0.0-20171026175957-610f3c86a089/api) github.com/hashicorp/consul/api v1.15.2 (/root/go/pkg/mod/github.com/hashicorp/consul/api@v1.15.2)
已尝试的操作
- 执行
go get github.com/hashicorp/consul/api@v1.15.2指定版本安装模块,未解决问题 - 错误使用本地路径执行
go mod download,触发路径格式错误:
go mod download /root/go/pkg/mod/github.com/hashicorp/consul@v0.0.0-20171026175957-610f3c86a089/api /root/go/pkg/mod/github.com/hashicorp/consul@v0.0.0-20171026175957-610f3c86a089/api: malformed module path "/root/go/pkg/mod/github.com/hashicorp/consul": empty path element
更新:已通过下载二进制文件解压完成安装,但Go命令安装方式的问题仍未解决。
解决Go命令安装的可行步骤
1. 清理冲突的模块缓存
先删除本地模块缓存中冲突的两个consul相关版本:
go clean -modcache github.com/hashicorp/consul@v0.0.0-20171026175957-610f3c86a089 go clean -modcache github.com/hashicorp/consul/api@v1.15.2
2. 用模块替换机制强制指定依赖版本
创建临时目录并初始化模块,通过替换规则统一依赖版本后安装:
mkdir temp-levant && cd temp-levant go mod init temp/levant go mod edit -replace github.com/hashicorp/consul/api=github.com/hashicorp/consul/api@v1.15.2 go install github.com/hashicorp/levant@latest
3. 安装Levant的兼容版本
部分旧版Levant依赖未拆分的consul模块,可尝试安装已知兼容的版本(比如v0.3.0):
go install github.com/hashicorp/levant@v0.3.0
内容的提问来源于stack exchange,提问作者loki
相关产品推荐
相关产品推荐

