Commit 978e89d0 authored by Ma_124's avatar Ma_124

GitHub ratelimiting

parent b851eb4c
Pipeline #53332623 failed with stages
in 1 minute and 8 seconds
......@@ -116,12 +116,24 @@ func fetchGitHub(repo string, ctx *Ctx) Meta {
if err != nil {
panic(err)
}
defer resp.Body.Close()
data, err = ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
resp.Body.Close()
_ = resp.Body.Close()
remaining, _ := strconv.Atoi(resp.Header.Get("X-RateLimit-Remaining"))
if remaining <= 1 {
reset, err := strconv.Atoi(resp.Header.Get("X-RateLimit-Reset"))
if err != nil {
panic(err)
}
println("GitHub: RateLimit: try again at " + time.Unix(int64(reset), 0).In(time.Local).Format("15:04:05"))
}
} else {
data = []byte(`{ "stargazers_count": 7654, "forks_count": 32, "open_issues_count": 1, "pushed_at": "2019-01-20T19:24:24Z" }`)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment