Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR modernizes the go-client transport layer by introducing composable http.RoundTripper middleware, improving streaming (SSE/NDJSON) handling, and updating docs/examples to match the new patterns.
Changes:
- Introduces
pkg/transportmiddleware (logging, recorder, OTel transport) and hooks to apply middleware client-wide (OptTransport) or per-request (OptReqTransport). - Improves streaming/SSE ergonomics (reconnect state in
TextStream) and adds anti-buffering headers for SSE/NDJSON requests. - Refactors rate limiting to be context-aware and adjusts decoding/content-type utilities and documentation.
Reviewed changes
Copilot reviewed 21 out of 22 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| transport.go | Removes old in-package logging transport implementation (replaced by pkg/transport). |
| clientopts.go | Adds OptTransport; updates OptTrace to use transport.NewLogging; switches option errors to httpresponse. |
| requestopts.go | Adds per-request transport middleware option (OptReqTransport); switches option errors to httpresponse. |
| client.go | Adds context-aware rate limiting helper, anti-buffering headers for streams, per-request shallow client copy + per-request transport wrapping, and text/plain decoding support. |
| textstream.go | Enhances SSE parsing and adds reconnect state (LastEventID, RetryDuration). |
| token.go | Changes Token.String() behavior for empty values. |
| payload.go | Adds MethodHead. |
| oauthflow.go | Refactors OAuth flow to accept context per method (instead of storing it). |
| pkg/transport/logging.go | New logging RoundTripper middleware (including streaming SSE logging). |
| pkg/transport/recorder.go | New recorder RoundTripper middleware for status/header capture. |
| pkg/transport/otel.go | Moves HTTP client tracing RoundTripper into pkg/transport. |
| pkg/transport/*.go tests | Adds tests for new middleware. |
| pkg/otel/span.go | Adjusts OpenTelemetry imports (aliases). |
| README.md | Updates docs for middleware, streaming, OAuth flow, and OTel usage patterns. |
| go.mod / go.sum | Removes github.com/gogo/protobuf dependency entry. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 22 out of 23 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request makes significant improvements to the
go-clientlibrary, especially around transport middleware, streaming support, and documentation. The changes introduce new options for plugging in HTTP middleware, improve rate limiting, enhance streaming event handling, and update the documentation to reflect these features.The most important changes are:
Transport Middleware and Client Options:
OptTransport(client-wide) andOptReqTransport(per-request) options, allowing users to easily add logging, tracing, and custom middleware. The documentation now highlights these options and provides usage examples. The deprecatedOptTraceis now documented as such and points users to the new middleware approach. [1] [2] [3] [4]OptTransportandtransport.NewTransport, and improved the related documentation and examples. [1] [2] [3]Streaming and SSE Improvements:
TextStreamEventdocumentation, detailing its fields and usage patterns for robust SSE handling.Rate Limiting and Request Handling:
waitRateLimitmethod that is context-aware, allowing cancellation via context and improving code clarity. [1] [2] [3]Content-Type Handling and Decoding:
text/plainresponses intostring,[]byte, orio.Writertypes. [1] [2] [3] [4]Documentation Updates:
These changes make the library more flexible, robust, and easier to use, especially for advanced HTTP client scenarios.