猿问

如何安装子命令?

我在 Go v. 1.15.8 darwin/amd64 中收到以下错误消息


main.go:8:2: cannot find package "github.com/google/subcommands" in any of:

/usr/local/go/src/github.com/google/subcommands (from $GOROOT)

/Users/user1/go/src/github.com/google/subcommands (from $GOPATH)

main.go 中的代码如下所示:


package main


import (

        "flag"

        "context"

        "os"


        "github.com/google/subcommands"

)

我知道子命令位于这里:https://github.com/google/subcommands 与git存储库在这里:https://github.com/google/subcommands.git


但是我该如何安装它呢?


当我这样做时:


go get github.com/google/subcommands

我收到以下错误消息:


# cd .; git clone -- https://github.com/google/subcommands /Users/user1/go/src/github.com/google/subcommands

Cloning into '/Users/user1/go/src/github.com/google/subcommands'...

fatal: unable to access 'https://github.com/google/subcommands/': Could not resolve host: github.com

package github.com/google/subcommands: exit status 128

当我打开我的Web浏览器并转到:https://github.com/google/subcommands/ 我可以看到网页没有问题。那么,为什么“go get”命令会遇到问题呢?


我做错了什么?


跃然一笑
浏览 167回答 1
1回答

守候你守候我

除了 git 配置之外,您还可以检查环境变量HTTP_PROXY/HTTPS_PROXY但更重要的是,检查添加是否会有所帮助(还有其他Go模块代理)GOPROXY=https://proxy.golang.org)这可以帮助从任何提供商,GitHub或其他提供商获取模块。
随时随地看视频慕课网APP

相关分类

Go
我要回答