我有一个可执行的 go 模块,我正在尝试执行以下命令go get github.com/saipraveen-a/number-manipulation/v2并得到这个错误:module github.com/saipraveen-a/number-manipulation@upgrade found (v1.0.1), but does not contain package github.com/saipraveen-a/number-manipulation/v2number-manipulation是一个不可执行的 go 模块,带有以下标签 v1.0.0、v1.0.1 和 v2.0.0。我是新来的。所以有人请告诉我这里有什么问题。带主包的模块应用程序.gopackage mainimport ( "fmt" "github.com/saipraveen-a/number-manipulation/calc" calcNew "github.com/saipraveen-a/number-manipulation/v2/calc")func main() { result := calc.Add(1, 2) fmt.Println("calc.Add(1,2) =>", result) result = calc.Add(1, 2, 3, 4, 5) fmt.Println("calc.Add(1,2,3,4,5) =>", result) newResult, err = calcNew.Add() if err != nil { fmt.Println("Error: =>", error) } else { fmt.Println("calcNew.Add(1,2,3,4) =>", calcNew.Add(1, 2, 3, 4)) }}去.modmodule maingo 1.14require github.com/saipraveen-a/number-manipulation v1.0.1go 版本 go1.14.3 darwin/amd64去环境GO111MODULE=""GOPATH="/Users/<user-id>/Golang"GOMOD="/Users/<user-id>/GoModules/main/go.mod"我试过 set GO111MODULE=on; 但这不会改变 GO111MODULE 的值# go build app.go go: finding module for package github.com/saipraveen-a/number-manipulation/v2/calcapp.go:7:2: module github.com/saipraveen-a/number-manipulation@latest found (v1.0.1), but does not contain package github.com/saipraveen-a/number-manipulation/v2/calc
1 回答
慕妹3242003
TA贡献1824条经验 获得超6个赞
您的 github 模块go.mod文件如下所示:
module github.com/saipraveen-a/number-manipulation
go 1.14
而您的客户端代码正在导入v2:
calcNew "github.com/saipraveen-a/number-manipulation/v2/calc"
如果要使用标记的版本,则v2.0.0需要将 github 模块的go.mod文件更改为:
module github.com/saipraveen-a/number-manipulation/v2
go 1.14
请注意,这会迫使您更改库本身内的导入路径。
然后要求v2进入您的客户端 go.mod 文件的路径:
module main
go 1.14
require github.com/saipraveen-a/number-manipulation/v2 v2.0.0
- 1 回答
- 0 关注
- 113 浏览
添加回答
举报
0/150
提交
取消