dongyong1942 2019-02-28 14:24
浏览 35

找不到提供套件的模组

I'm not sure how to solve a dependency issue I'm finding with "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

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
", 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

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
", 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
  • 写回答

1条回答 默认 最新

  • dongxin8392 2019-02-28 14:39
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度