Ita*_*chi 6 oauth github go aws-code-deploy
我们使用AWS代码部署将Github项目部署到Ec2实例,每次部署它时都会要求Github用户名和密码来下载存储库.找到以下解决方法
为PHP存储库设置Oauth是通过在composer auth.json .composer/auth.json中添加它来完成的.
{
"http-basic": {},
"github-oauth": {"github.com": "xyzasasasauhu"}
}
Run Code Online (Sandbox Code Playgroud)
但是找不到为Golang项目做这个的方法.通常我们希望实现go get https://github.com/username/reponame,而无需明确提供凭据.
这个问题有两种解决方案:
不要用于go get获取您的私人 GitHub 存储库的代码。只要代码最终位于正确的子目录 ( $GOPATH/src/github.com/org/project) 中,Go 并不关心它是如何到达那里的。只需在构建脚本中添加一些命令即可:
DIR=$GOPATH/src/github.com/org/project
TOKEN=yourtoken
if [ -d $DIR ]; then
cd $DIR
git reset --hard
git clean -dfx
else
mkdir -p $DIR
cd $DIR
git init
fi
git pull https://$TOKEN@github.com/org/project.git
Run Code Online (Sandbox Code Playgroud)