go - 找不到提供包的模块
问题描述
我不确定如何解决我在“go mod”中发现的依赖问题。据我所知,它正在获取一些子依赖项的错误版本,这些子依赖项指向一个不再存在的存储库。
我很新,所以我确定我搞砸了,我很想得到一些帮助来了解如何解决这个问题。请检查以下示例:
使用 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"
但是,使用 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"
我如何让最后一个工作?
$ go version
go version go1.12 darwin/amd64
解决方案
According to the Go modules wiki
Day-to-day upgrading and downgrading of dependencies should be done using 'go get', which will automatically update the go.mod file. Alternatively, you can edit go.mod directly.
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.
So go getting your dependencies is fine.
Go modules on the other hand will according to the wiki again provide certain functionalities:
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).
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.
推荐阅读
- iteration - 每个数据的 Scipy.optimize.minimize
- python - 如何绘制带有误差线的线性回归?
- android - 错误“未安装应用程序”的原因
- javascript - 返回数组数组中为真的元素
- python - Pandas:读取没有列标题且数据不是从第一行开始的excel
- go - Golang gorm URL 转义
- flutter - 未处理的异常:类型'String'不是颤振中类型'num'的子类型
- java - 使用 LambdaMetaFactory 调用任意构造函数
- reactjs - 无法安装 expo 依赖项
- c# - 尝试从 c# 插入 Access 数据库时出现 OLEDB 错误 E_OUTOFMEMORY (0x8007000E)