我正在尝试使用OAuth令牌从gitlab获取回购列表。
我的代码看起来像这样。。。(“github.com/xanzy/go-gitlab”)
repositories := []string{}
client, _ := gitlab.NewClient(gitRepoRequest.Token, gitlab.WithBaseURL("https://gitlab.com/api/v4"))
fmt.Println("client...", client.ContainerRegistry)
projects, _, projectListErr := client.Projects.ListProjects(&gitlab.ListProjectsOptions{})
for _, project := range projects {
fmt.Println("ID===", project.ID)
fmt.Println("NAME===", project.Name)
}
if projectListErr != nil {
// return err
}
我无法得到项目清单。。“projectListErr”说。。。
GET https://gitlab.com/api/v4/projects: 401 {message: 401 Unauthorized}
我对令牌值很有信心,因为我得到了使用同一令牌的回购的所有分支的列表,该代码看起来像。。。(“github.com/go-git/go-git/v5”)
rem := git.NewRemote(gitMemory.NewStorage(), &gitConfig.RemoteConfig{
Name: "origin",
URLs: []string{gitBranchesRequest.Repository},
})
refs, listErr := rem.List(&git.ListOptions{
Auth: &gitHttp.BasicAuth{Username: gitUserName, Password: gitBranchesRequest.Token},
})
这是否意味着我使用的图书馆存在问题?
github.com/xanzy/go-gitlab