你如何安装子命令?

How do you install subcommands?

我在 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

当我打开网络浏览器并转到:https://github.com/google/subcommands/ 我可以毫无问题地查看网页。那么为什么“go get”命令会遇到这个问题?

我做错了什么?

除了 git 配置外,您还可以检查 HTTP_PROXY/HTTPS_PROXY

的环境变量

但更重要的是,检查添加 GOPROXY=https://proxy.golang.org 是否有帮助(有 other Go module proxies as well

这可能有助于从任何供应商 GitHub 或其他供应商处获取模块。