如何使用go-github获取golang/go的发行版 [英] How to get releases for golang/go with go-github

查看:74
本文介绍了如何使用go-github获取golang/go的发行版的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

学习Go并尝试使用go-github获取golang/go的发行列表.

Learning Go and try to get the release list of golang/go with go-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)

}

当我运行它时,发布列表为空(如下所示):

When I run it, the release list is empty (as below):

[]

github.Rate{Limit:60, Remaining:59, Reset:github.Timestamp{2015-12-05 14:47:55 +1100 AEDT}}

我不知道我在做什么错.

I don't know what I am doing wrong.

推荐答案

仔细研究一下Go存储库,这些发行版实际上只是标签,而不是Github发行版,这就是为什么它返回空数组的原因.试试这个:

Taking a closer look at the Go repository, the releases are actually just tags and not Github releases, that's why it's returning an empty array. Try this:

// https://api.github.com/repos/jp9000/obs-studio/releases
releases, rsp, err := client.Repositories.ListReleases("jp9000", "obs-studio", opt)

这应该正确返回jp9000的obs-studio存储库的所有发行版.

This should correctly return all releases for jp9000's obs-studio repository.

原始答案:

看一下文档,代码看起来不错,但是这可能是Github API的问题.例如,如果您转到 https://api.github.com/repos/golang/go/releases 会得到一个空数组,但是如果您使用搜索标签https://api.github.com/repos/golang/go/tags ,它列出了所有任务,没有任何问题.

Looking at the docs, the code looks good but this might be an issue with Github's API though. For instance, if you go to https://api.github.com/repos/golang/go/releases you get an empty array, but if you search for the tags using https://api.github.com/repos/golang/go/tags it lists all tasks without any problem.

如果您转到 https://api.github.com/repos/golang/go/releases/1 会得到404.我从Github开发人员页面获取了这些地址:

And if you go to https://api.github.com/repos/golang/go/releases/1 you get a 404. I took these addresses from the Github Developer's page: https://developer.github.com/v3/repos/releases/#list-releases-for-a-repository

这篇关于如何使用go-github获取golang/go的发行版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆