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

时间:2020-07-08 08:41:17

标签: go go-modules go-get go-build go-packages

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

数字操作是具有以下标记的不可执行的go模块 v1.0.0,v1.0.1和v2.0.0。

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

带主包装的模块

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

运行版本go1.14.3 darwin / amd64

转到环境

GO111MODULE=""
GOPATH="/Users/<user-id>/Golang"
GOMOD="/Users/<user-id>/GoModules/main/go.mod"

我尝试将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

1 个答案:

答案 0 :(得分:0)

您的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

请注意,这迫使您更改库中的导入路径 本身。

然后在您的客户端go.mod文件中输入v2路径:

module main

go 1.14

require github.com/saipraveen-a/number-manipulation/v2 v2.0.0
相关问题