本文整理匯總了Golang中github.com/google/go-github/github.Client.RateLimit方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.RateLimit方法的具體用法?Golang Client.RateLimit怎麽用?Golang Client.RateLimit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/google/go-github/github.Client
的用法示例。
在下文中一共展示了Client.RateLimit方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: printRateLimit
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: exceededRateLimit
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
}