问题描述
我在 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 config 之外,您还可以检查 HTTP_PROXY
/HTTPS_PROXY
的环境变量
但更重要的是,检查添加 GOPROXY=https://proxy.golang.org
是否有帮助(有 other Go module proxies as well)
这有助于从任何提供商、GitHub 或其他人处获取模块。