vartanbeno / go-reddit

Go library for accessing the Reddit API.
Other
310 stars 84 forks source link

Question: does this package automatically handle abiding by rate limits #47

Closed Tiger-I-Yang closed 4 months ago

Tiger-I-Yang commented 8 months ago

if I were to spam call subreddit.NewPosts(), will the method just block as nessecary to skirt just under reddit's rate limit, or will it just return any rate limit errors

sesopenko commented 4 months ago

Looking at the source code, no it doesn't. In any given Response object returned by one of the client services, you can check the Rate object to see if there's rate limit remaining.

When the library makes an api call, if reddit has a response header stating there's no rate limit left, the library will return a RateLimitError and you'll have to implement your own throttling logic to handle that.

Unfortunately, the library will return a RateLimmitError if there's no rate limit left, even if the request was fulfilled by reddit (ie: you used your last api call left for the 10 minute period). It won't return with a populated result in this case. See source code here

If CheckResponse returns a rate limit error, it short circuits out and doesn't build the actual response from the body, which is a bug in my opinion.

I'm investigating other libraries to see if there's something out there with more robust rate limit handling.

Tiger-I-Yang commented 4 months ago

I see, thanks!

Tiger-I-Yang commented 4 months ago

a