Golang中"go get"无法工作 - 无效的仓库名称问题解决
Golang中"go get"无法工作 - 无效的仓库名称问题解决 我正在尝试从git获取mysql包,但一直遇到以下错误:
go get -u -v github.com/go-sql-driver/mysql
github.com/go-sql-driver/mysql (download)
# cd .; git clone https://github.com/go-sql-driver/mysql /root/go/src/github.com/go-sql-driver/mysql
Cloning into '/root/go/src/github.com/go-sql-driver/mysql'...
fatal: remote error:
/go-sql-driver/mysql is not a valid repository name
Email support@github.com for help
到目前为止,GitHub支持也未能帮助我解决这个问题。
我也尝试过使用git clone命令,但得到了相同的结果。
我使用的服务器运行的是CentOS Linux release 7.1.1503 (Core),并安装了git版本2.20.1。
更多关于Golang中"go get"无法工作 - 无效的仓库名称问题解决的实战教程也可以访问 https://www.itying.com/category-94-b0.html
我将操作系统更新至 CentOS Linux 7.6.1810(核心版),并下载安装了 Git 1.8.3.1 版本,但仍然遇到相同的错误信息。
我无法复现这个问题。你使用的是相当旧的 CentOS 7 版本。当前版本是 CentOS Linux release 7.6.1810 (Core)。你能更新一下吗?
最新版本中的 git 版本是 1.8.3.1。所以你安装了一个较新的版本。你能用 centos 仓库中的版本测试一下吗?
我在 /etc/yum.repos.d 目录中添加了 wandisco-git.repo 文件,内容如下:
[wandisco-git]
name=Wandisco GIT Repository
baseurl=http://opensource.wandisco.com/centos/7/git/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://opensource.wandisco.com/RPM-GPG-KEY-WANdisco
这使我能够加载 git 版本 1.8.3.1
问题出现在GitHub仓库的URL格式上。错误信息表明Git无法识别该仓库路径,这通常与网络配置或Git协议问题相关。以下是几种解决方案:
方案1:使用完整HTTPS URL
go get -u -v github.com/go-sql-driver/mysql
如果上述命令仍然失败,尝试:
git config --global http.sslVerify false
go get -u -v github.com/go-sql-driver/mysql
方案2:直接使用Git命令测试
# 测试Git克隆
git clone https://github.com/go-sql-driver/mysql.git /tmp/test-mysql
# 如果HTTPS失败,尝试SSH方式
git clone git@github.com:go-sql-driver/mysql.git /tmp/test-mysql
方案3:手动下载并安装
# 创建工作目录
mkdir -p $GOPATH/src/github.com/go-sql-driver
cd $GOPATH/src/github.com/go-sql-driver
# 下载源码
wget https://github.com/go-sql-driver/mysql/archive/master.zip
unzip master.zip
mv mysql-master mysql
# 安装包
cd mysql
go install
方案4:检查网络和DNS配置
# 测试网络连通性
ping github.com
# 检查DNS解析
nslookup github.com
# 检查Git配置
git config --list
方案5:使用代理(如果网络受限)
# 设置HTTP代理
export http_proxy=http://your-proxy:port
export https_proxy=https://your-proxy:port
# 或者使用Git配置代理
git config --global http.proxy http://your-proxy:port
验证安装
安装成功后,创建测试文件验证:
package main
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
)
func main() {
fmt.Println("MySQL driver loaded successfully")
// 测试数据库连接
db, err := sql.Open("mysql", "user:password@/dbname")
if err != nil {
fmt.Println("Error:", err)
return
}
defer db.Close()
err = db.Ping()
if err != nil {
fmt.Println("Ping error:", err)
return
}
fmt.Println("MySQL connection successful")
}
最常见的原因是网络代理配置或Git版本兼容性问题。CentOS 7上的Git 2.20.1应该足够新,但可以尝试升级到最新版本。


