Skip to content

Conversation

@doron-sincere
Copy link
Member

Changes

  • Add functional options pattern to NewBatcher:
    • WithHTTPClient: custom HTTP client
    • WithRetries: configurable retry count
    • WithEZKey: override EZ key after construction
  • Update golog to v1.0.0
  • Remove redundant root go.mod
  • Replace deprecated ioutil with io

Verification

  • Build passes
  • Tests pass with race detector

- Add WithHTTPClient option for custom http.Client injection
- Add WithRetries option for configurable retry count (default: 2)
- Convert send() to receiver method to access Batcher config
- Replace ioutil.ReadAll with io.ReadAll
- Replace interface{} with any
- Fix defer inside loop anti-pattern
- Fix PostEZCountTime docstring
Copy link
Contributor

@AObuchow AObuchow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :), my comments are just nits from previously existing code.

// If not provided, defaults to 2.
func WithRetries(n int) Option {
return func(b *Batcher) {
if n > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Could we not allow setting 0 retries, i.e. if n >= 0 {...} ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pre-existing default behavior was hardcoded 2 attempts, I believe. Retry logic can easily be updated to be >= (and also updated in the b.send() method to actually act as retries, rather than attempts. Good call.

for i := 0; i < retries; i++ {
resp, err := http.DefaultClient.Do(req)
func (b Batcher) send(req *http.Request) {
for i := 0; i < b.retries; i++ {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Isn't this technically "attempts" not "retries"? E.g. if b.retries == 1 then we only make a single request attempt, we don't actually retry it one time.

To be more accurate, the for loop should be i <= b.retries or we should rename retries to attempts (though that's less standard).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed - will update (and see other response as well)

- Allow setting 0 retries via `n >= 0` validation (single attempt)
- Change default from 2 to 1 to preserve existing behavior (2 total attempts)
- Rewrite send() with idiomatic infinite loop pattern
- Update doc comment to clarify: retries=0 means no retries (1 attempt),
  retries=N means N retries (N+1 total attempts)
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.

3 participants