使用go-git/v5
并尝试克隆https
如下:
_, err := git.Clone(memory.NewStorage(), fs, &git.CloneOptions{
URL: repo,
ReferenceName: plumbing.ReferenceName(branch),
Depth: 1,
SingleBranch: true,
Auth: &http.TokenAuth{Token: string(token)},
})
token
表单的字符串在哪里ghp_XXXXXXXXX
(我的个人 GH 访问令牌)
repo
等于我的私人回购https://github.com/pkaramol/arepo
错误是
"net/http: invalid header field value \"Bearer ghp_XXXXXXXXX`\\n\" for key Authorization"
我还尝试将基本身份验证与我的用户名和令牌作为密码一起使用
_, err := git.Clone(memory.NewStorage(), fs, &git.CloneOptions{
URL: repo,
ReferenceName: plumbing.ReferenceName(branch),
Depth: 1,
SingleBranch: true,
Auth: &http.BasicAuth{Username: "pkaramol", Password: token},
})
现在错误变为:
authentication required
通过https克隆的正确方法是什么?
该令牌具有repo
范围 fwiw
编辑:
实例化fs
如下
fs := memfs.New()
使用的http
包如下
"github.com/go-git/go-git/v5/plumbing/transport/http"