学习Go并尝试获取golang/go with github的发布列表。
这是我的代码:
package main
import (
"github.com/google/go-github/github"
"fmt"
)
func main() {
client := github.NewClient(nil)
opt := &github.ListOptions{Page: 2, PerPage: 10}
releases, rsp, err := client.Repositories.ListReleases("golang", "go", opt)
if err != nil {
fmt.Println(err)
}
fmt.Printf("\n%+v\n", releases)
fmt.Printf("\n%+v\n", rsp)
}当我运行它时,发布列表是空的(如下所示):
[]
github.Rate{Limit:60, Remaining:59, Reset:github.Timestamp{2015-12-05 14:47:55 +1100 AEDT}}我不知道我做错了什么。
发布于 2015-12-05 04:48:55
编辑:
仔细看看Go存储库,这些版本实际上只是标记,而不是Github版本,这就是它返回空数组的原因。试试这个:
// https://api.github.com/repos/jp9000/obs-studio/releases
releases, rsp, err := client.Repositories.ListReleases("jp9000", "obs-studio", opt)这应该会正确地返回for 9000的obs-studio存储库的所有版本。
原始答案:
看一下文档,代码看起来不错,但这可能是Github的API的一个问题。例如,如果您转到https://api.github.com/repos/golang/go/releases,就会得到一个空数组,但是如果您使用https://api.github.com/repos/golang/go/tags搜索标记,它会列出所有任务,没有任何问题。
如果你去https://api.github.com/repos/golang/go/releases/1,你会得到404分。我从Github开发人员的页面上获取了这些地址:https://developer.github.com/v3/repos/releases/#list-releases-for-a-repository
https://stackoverflow.com/questions/34100738
复制相似问题