New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make Period field public on Rate struct #35
Conversation
As #35 was coming in, I noticed that as of Go 1.10, `go vet` complains about the use of unkeyed fields in composite literals: ``` go vet ./... ./example_test.go:26: github.com/throttled/throttled.RateQuota composite literal uses unkeyed fields ./example_test.go:51: github.com/throttled/throttled.RateQuota composite literal uses unkeyed fields ./http_test.go:19: github.com/throttled/throttled.RateLimitResult composite literal uses unkeyed fields ./http_test.go:23: github.com/throttled/throttled.RateLimitResult composite literal uses unkeyed fields ./rate_test.go:41: github.com/throttled/throttled.RateQuota composite literal uses unkeyed fields ./rate_test.go:114: github.com/throttled/throttled.RateQuota composite literal uses unkeyed fields ``` Which is unfortunately failing the build for the `1.x` version. This patch names fields wherever we were using the unkeyed kind.
rate.go
Outdated
@@ -78,7 +78,7 @@ func (r *rateLimitResult) RetryAfter() time.Duration { return r.retryAfter } | |||
// Rate describes a frequency of an activity such as the number of requests | |||
// allowed per minute. | |||
type Rate struct { | |||
period time.Duration // Time between equally spaced requests at the rate | |||
Period time.Duration // Time between equally spaced requests at the rate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that this is a public field, could you move the comment up to appear above it and change it to follow go convention to read something like "Period is the amount of time between equally spaced requests for this rate."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, thanks, I didn't realize side comments were treated differently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure they are, but the important part is to have the documentation start with the field name (i.e., "Period ...") because that's a Go convention for public field documentation that Golint will complain about if not followed. (Moving the comment above just gives us a little more space.)
this can be useful for custom implementations of RateLimiter that need to reflect on the configured period for calculations. one example is github.com/keratin/throttled-valve.
The Period field can can be useful for third-party implementations of RateLimiter that need to reflect on the configured period for calculations. One example is described in #34.