繁体   English   中英

Go 在获取主要版本模块依赖项时出错

[英]Go get error while getting major version module dependency

我有一个可执行的 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/v2

number-manipulation是一个不可执行的 go 模块,带有以下标签 v1.0.0、v1.0.1 和 v2.0.0。

我是 go 的新手。 所以有人请告诉我这里有什么问题。

主模块package

app.go

package main

import (
    "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))
    }
}

go.mod

module main

go 1.14

require github.com/saipraveen-a/number-manipulation v1.0.1

go版本go1.14.3 darwin/amd64

go 环境

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/calc

app.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

您的 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 的版本,则需要将v2.0.0模块的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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM