简体   繁体   English

找不到提供套件的模组

[英]Cannot find module providing package

I'm not sure how to solve a dependency issue I'm finding with "go mod". 我不确定如何使用“ go mod”解决依赖项问题。 From what I could gather, it's fetching the wrong version of some sub-dependency which points to a repo that doesn't exist anymore. 据我所知,它正在获取某个子依赖关系的错误版本,该依赖关系指向不再存在的存储库。

I very very new to go so I'm sure I'm screwing up, I'd love some help to understand how to fix this. 我刚去很新,所以我确定我正在搞砸,我很乐意为您提供一些帮助,以帮助您了解如何解决此问题。 Please check these examples: 请检查以下示例:

Getting my only dependency with go get works fine 用go get获得我唯一的依赖关系很好

export GOPATH=`mktemp -d`
export MYAPP=`mktemp -d`
cd $MYAPP

cat << EOF > main.go
package main
import (
  "fmt"
  "os"
  "github.com/kubernetes/minikube/pkg/storage"
)
func main() {
  if err := storage.StartStorageProvisioner(); err != nil {
    fmt.Printf("Error starting provisioner: %v\n", err)
    os.Exit(1)
  }
}
EOF

go get github.com/kubernetes/minikube/pkg/storage
go build && echo "WORKED" || echo "FAILED"

However, getting it with go mod doesn't work 但是,通过go mod获取它不起作用

export GOPATH=`mktemp -d`
export MYAPP=`mktemp -d`
cd $MYAPP

cat << EOF > main.go
package main
import (
  "fmt"
  "os"
  "github.com/kubernetes/minikube/pkg/storage"
)
func main() {
  if err := storage.StartStorageProvisioner(); err != nil {
    fmt.Printf("Error starting provisioner: %v\n", err)
    os.Exit(1)
  }
}
EOF

go mod init github/my/repo
go build && echo "WORKED" || echo "FAILED"

How do I get this last one working? 我如何使最后一个工作?

$ go version
go version go1.12 darwin/amd64

According to the Go modules wiki 根据Go模块Wiki

Day-to-day upgrading and downgrading of dependencies should be done using 'go get', which will automatically update the go.mod file. 日常的依赖关系升级和降级应该使用“ go get”完成,它将自动更新go.mod文件。 Alternatively, you can edit go.mod directly. 或者,您可以直接编辑go.mod。

To the extent that I've understood go mod init won't go get your dependencies, rather it'll initialize a new module and create a mod file to track the dependency versions that your module is using. 就我所知,go mod init不会获得您的依赖关系,而是会初始化一个新模块并创建一个mod文件来跟踪您模块所使用的依赖关系版本。

So go getting your dependencies is fine. 因此,去获取您的依赖关系很好。

Go modules on the other hand will according to the wiki again provide certain functionalities: 另一方面,根据Wiki,Go模块再次提供某些功能:

Standard commands like go build or go test will automatically add new dependencies as needed to satisfy imports (updating go.mod and downloading the new dependencies). 诸如go buildgo test之类的标准命令将根据需要自动添加新的依赖关系,以满足导入要求(更新go.mod并下载新的依赖关系)。

When needed, more specific versions of dependencies can be chosen with commands such as go get foo@v1.2.3, go get foo@master, go get foo@e3702bed2, or by editing go.mod directly. 需要时,可以使用诸如go get foo@v1.2.3,go foo @ master,go foo @ e3702bed2之类的命令选择更具体的依赖版本,或者直接编辑go.mod。

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

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