我有一個可執(zhí)行的 go 模塊,我正在嘗試執(zhí)行以下命令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是一個不可執(zhí)行的 go 模塊,帶有以下標簽 v1.0.0、v1.0.1 和 v2.0.0。我是新來的。所以有人請告訴我這里有什么問題。帶主包的模塊應(yīng)用程序.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去環(huán)境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條經(jīng)驗 獲得超6個贊
您的 github 模塊go.mod文件如下所示:
module github.com/saipraveen-a/number-manipulation
go 1.14
而您的客戶端代碼正在導(dǎo)入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
請注意,這會迫使您更改庫本身內(nèi)的導(dǎo)入路徑。
然后要求v2進入您的客戶端 go.mod 文件的路徑:
module main
go 1.14
require github.com/saipraveen-a/number-manipulation/v2 v2.0.0
- 1 回答
- 0 關(guān)注
- 154 瀏覽
添加回答
舉報
0/150
提交
取消