Skip to content
liuxiaobo
Go back

golang实现 GitHub 私有代理

go get liuxiaobo.me/go-crate 走自定义域名,实际拉 github.com/liuxiaobopro/go-crate。

Table of contents

Open Table of contents

自定义域名

在 https://liuxiaobo.me/go-crate 返回这段 HTML(Go 会请求 ?go-get=1):

<!doctype html>
<html>
  <head>
    <meta
      name="go-import"
      content="liuxiaobo.me/go-crate git https://github.com/liuxiaobopro/go-crate"
    />
  </head>
  <body>
    go-crate
  </body>
</html>

设置环境变量

go env -w GOPRIVATE=liuxiaobo.me/*
go env -w GONOSUMDB=liuxiaobo.me/*
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
git config --global url."git@github.com:".insteadOf "https://github.com/"

GOPRIVATE 跳过代理和 checksum 校验。最后一行把 GitHub HTTPS 改成 SSH,私有仓库才能拉下来。

生成密钥

ssh-keygen -t ed25519 -C "liuxiaobopro@qq.com"
ssh-keygen -t rsa -b 4096 -C "liuxiaobopro@qq.com"

查看公钥

cat ~/.ssh/id_ed25519.pub
cat ~/.ssh/id_rsa.pub

PowerShell:

Get-Content $env:USERPROFILE\.ssh\id_ed25519.pub
Get-Content $env:USERPROFILE\.ssh\id_rsa.pub

公钥加到 GitHub:Settings → SSH and GPG keys。私钥不要外传。



Previous Post
生成和查看 SSH 密钥