Пример #1
0
func printRateLimit(client github.Client) {
	rate, _, err := client.RateLimit()
	if err != nil {
		fmt.Println("Error fetching rate limit:", err)
	} else {
		remaining := int(rate.Reset.Sub(time.Now()).Seconds())
		mins := remaining / 60
		secs := remaining % 60
		fmt.Printf("API Rate Limit: %d/%d remaining for %dm %ds \n\n", rate.Remaining, rate.Limit, mins, secs)
	}
}
Пример #2
0
func exceededRateLimit(client *github.Client) bool {
	rate, _, err := client.RateLimit()
	if err != nil {
		fmt.Printf("Error checking rate limit: %s\n", err)
		return false
	}
	// Check for a margin sufficient to run both examples.
	if rate.Remaining < 4 {
		fmt.Printf("Exceeded (or almost exceeded) GitHub API rate limit: %s. Try again later.\n", rate)
		return true
	}
	return false
}