refactor(sdk): refactor Go SDK client#1916
Merged
Merged
Conversation
haze518
reviewed
Jun 28, 2025
…e consistence with rust sdk.
… call it when build
…some problem found in review.
279db43 to
fe32d0b
Compare
…) logic - Refactored `GetConsumerGroup` and `GetConsumerGroups` functions in `Client` - Renamed `iggcon.ConsumerKind`, since `ConsumerGroup` should be used as the element type in the `GetConsumerGroups` response - Update the test files. - Add TODO in DeserializeToConsumerGroupDetails. The implementation should be done in the future.
…rGroup for consistency with DeserializeConsumerGroups.
Contributor
Author
|
All function signatures and return types have been updated. Required arguments are passed directly, while optional arguments are represented as pointer values. I try to limit the scope of changes in this PR to function signatures and their usage logic, as this pr is already too huge. However, I had to modify some functions—mainly in the serialization layer—to align with the updated argument and return value structure. For more detail. Please check the comments I provided in review. |
chengxilo
commented
Jul 3, 2025
chengxilo
commented
Jul 3, 2025
chengxilo
commented
Jul 3, 2025
chengxilo
commented
Jul 3, 2025
chengxilo
commented
Jul 3, 2025
chengxilo
commented
Jul 3, 2025
haze518
approved these changes
Jul 4, 2025
spetz
approved these changes
Jul 4, 2025
hageshiame
pushed a commit
to hageshiame/iggy
that referenced
this pull request
Nov 7, 2025
- Refactored the Go SDK client creation logic using the option pattern. - Updated the client interface and TCP client methods to align closely with the Rust SDK: - Replaced struct-based parameters with explicit argument lists. - Used pointers to represent optional arguments. - Edited some return type to align with rust SDK. - Changed all related tests to reflect the updated interface and logic.
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.

Edited in July 2, 2025 (GMT-4), to reflect the latest change.
Description
What I did
Refactored the Go SDK client creation logic using the option pattern.
Updated the client interface and TCP client methods to align closely with the Rust SDK:
Changed all related tests to reflect the updated interface and logic.
Future work
The goal of this PR is to align the API surface and usage pattern with the Rust SDK — not to fully implement every internal behavior. Since there are some logic not implemented yet, I add some TODO in those part.
Some explanation (Outdated, kept for history)
What I did
Why we need to refactor it.
( I copied the message I sent in discord a few days ago here)
Since currently, the golang sdk is very out dated and when we create a client the
in rust when we create client:
While in golang we create client:
Since the Rust SDK is considered the primary or canonical implementation, it makes sense for other language SDKs to follow its design principles closely — including using the same repository name and similar function names. Clearly, the current Go SDK does not meet this requirement: its function names don’t clearly describe their purpose, and the overall design pattern feels less elegant.
My solution
So what I did is to read the rust sdk source code and ... almost directly ported its logic to Go. I want to explain why I decided not to use the option pattern discussed earlier with @haze518, even though the option pattern is commonly considered best practice in Go. At first, I choose to follow the example of https://github.com/nats-io/nats.go/blob/main/nats.go#L867 . It's elegent, but it would not work so well in our use case, since we need to support tcp/http/quic three different protocol and they have different options.
Here is a simplified example showing the potential issue:
So, I think it is not a good choice as I don't know how to solve this problem while using option pattern. But if we use builder pattern, it allows us to control and constrain users’ choices more effectively, preventing invalid combinations and leading to a cleaner, safer API.
so currently, after this pr, the usage of it would be: