GoLand import go module public repo 失败,版本无效

标签 go goland go-modules

我想将我创建的模块导入另一个项目。源代码在 GitHub 中,在公共(public)存储库中,但尝试在 GoLand 中导入时出现以下错误:

go: finding module for package github.com/ambye85/gophercises/link
go: downloading github.com/ambye85/gophercises/link v0.0.0-20200323082040-d484a876f7e8
go: downloading github.com/ambye85/gophercises v0.0.0-20200323082040-d484a876f7e8
github.com/ambye85/gophercises/sitemap imports
    github.com/ambye85/gophercises/link: github.com/ambye85/gophercises/link@v0.0.0-20200323082040-d484a876f7e8: verifying module: github.com/ambye85/gophercises/link@v0.0.0-20200323082040-d484a876f7e8: reading https://sum.golang.org/lookup/github.com/ambye85/gophercises/link@v0.0.0-20200323082040-d484a876f7e8: 410 Gone
    server response:
    not found: github.com/ambye85/gophercises/link@v0.0.0-20200323082040-d484a876f7e8: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /tmp/gopath/pkg/mod/cache/vcs/a488fe783593bd6e7b765f40dfed37c7e534d0a80ca8e1bff63e11e21f02e8fd: exit status 128:
        fatal: could not read Username for 'https://github.com': terminal prompts disabled

我所做的所有搜索似乎都表明这是由于尝试访问私有(private)仓库造成的。这里情况不同。

有谁知道原因和解决方法是什么?
go env 的输出:
go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/ashleyb/Library/Caches/go-build"
GOENV="/Users/ashleyb/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/ashleyb/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.14/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.14/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/pn/8n7495nd5yn6mxxthgv5ghqhtn2mwj/T/go-build279336926=/tmp/go-build -gno-record-gcc-switches -fno-common"

最佳答案

可以使用以下方法修复:

$ git config --global --add url."git@github.com:".insteadOf "https://github.com/"

当您尝试使用 https 进行身份验证时,可能会出现此问题。但是您启用了 2FA。这可以通过强制 git 使用 ssh 来解决对于所有交互。

资源:
  • Adding a new SSH key to your GitHub account
  • Blog post
  • 关于GoLand import go module public repo 失败,版本无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60810386/

    相关文章:

    google-app-engine - GAE中如何导入本地Go包

    sql - Goland 可以使用其他 SQL 包自动完成 SQL 语句吗?

    go - 自动导入 3rd 方包

    go - 下载后可以在模块中生成代码吗?

    go - 使用 Go 模块时生成 in-repo protos 的最佳实践

    当 SessionStore 来自导出包时未设置 Gorilla/sessions cookie

    go - 为什么访问是 RDWR 时内存映射文件需要刷新?

    multithreading - golang可以启动多线程来处理网络IO吗

    debugging - Goland 无法在 macos 上运行调试

    go mod download 不会下载单个库;如何在不操作整个 vendor 缓存的情况下修改导入单个库