Golang执行go env -w GOPRIVATE=github.com/TecXLab/*时报错如何解决
Golang执行go env -w GOPRIVATE=github.com/TecXLab/*时报错如何解决 我想在Go代码中使用私有仓库,但在执行go get命令时遇到了错误。
当我执行命令 go env -w GOPRIVATE=github.com/TecXLab/* 时,它给出了以下错误:
zsh: no matches found: GOPRIVATE=github.com/TecXLab/*
我使用的是Mac M1芯片。 已安装Visual Studio Code。 Go版本为 go1.17.9 darwin/arm64。
感谢您的帮助。 使用反斜杠解决了错误。
更多关于Golang执行go env -w GOPRIVATE=github.com/TecXLab/*时报错如何解决的实战系列教程也可以访问 https://www.itying.com/category-94-b0.html
只需删除 *。它是不需要的。
* 符号是由你的 shell 解释的。
你需要根据你的 shell 规则对其进行转义。使用反斜杠或单引号应该可以。
在 macOS 的 zsh 中,* 会被 shell 解释为通配符,导致命令解析错误。需要转义 * 或使用引号包裹整个值。
以下是解决方案:
方案一:使用引号包裹值
go env -w 'GOPRIVATE=github.com/TecXLab/*'
方案二:转义通配符
go env -w GOPRIVATE=github.com/TecXLab/\*
方案三:使用双引号
go env -w "GOPRIVATE=github.com/TecXLab/*"
执行成功后,验证设置:
go env GOPRIVATE
输出应为:
github.com/TecXLab/*
补充说明: 如果还需要设置其他私有仓库,可以用逗号分隔:
go env -w 'GOPRIVATE=github.com/TecXLab/*,gitlab.com/yourcompany/*'
私有仓库认证配置示例:
设置 GOPRIVATE 后,通常需要配置 git 凭证访问私有仓库。编辑 ~/.gitconfig:
[url "git@github.com:"]
insteadOf = https://github.com/
或在 ~/.netrc 中添加:
machine github.com
login your-username
password your-token
验证私有仓库访问:
go get -v github.com/TecXLab/your-private-repo

