Skip to content
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

Closed
wants to merge 1 commit into from
Closed

make Period field public on Rate struct #35

wants to merge 1 commit into from

Conversation

cainlevy
Copy link

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.

brandur added a commit that referenced this pull request Mar 13, 2018
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
Copy link
Member

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."

Copy link
Author

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.

Copy link
Member

@brandur brandur Mar 13, 2018

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.)

@brandur
Copy link
Member

brandur commented Mar 13, 2018

@cainlevy Left a comment above, but otherwise looks good. Thanks!

I think your build failures are due to a problem on master caused by 1.10's go vet to become a little discerning about styling in code. I just merged #36 and if you rebase, it should go green.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants