Conversation
Refactored ThreeCommasClient to store configuration fields directly on the
struct instead of using a separate clientConfig. This allows users to pass
through oapi-codegen ClientOptions for middleware, logging, and request
modification.
Changes:
- Moved config fields (baseURL, apiKey, etc.) to ThreeCommasClient struct
- Added clientOptions []ClientOption field to store pass-through options
- Added WithClientOption() to accept ClientOption functions
- ThreeCommasClientOption now operates on *ThreeCommasClient directly
- User-provided request editors run before RSA signer for proper logging
This design enables future middleware additions like WithLogger() and
WithOpenTelemetry() as ThreeCommasClientOptions that internally use
WithRequestEditorFn.
Example usage:
client, err := threecommas.New3CommasClient(
threecommas.WithAPIKey("key"),
threecommas.WithPrivatePEM(pem),
threecommas.WithClientOption(
threecommas.WithRequestEditorFn(loggerFunc),
),
)
Added comprehensive documentation for the new WithClientOption functionality: - New "Middleware and Request Customization" section with examples - Updated Features section to highlight middleware support - Explains execution order (middleware runs before RSA signer) - Lists common use cases: logging, monitoring, OpenTelemetry, custom headers This documents the restored WithRequestEditorFn capability through the WithClientOption wrapper.
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.
Summary
Restores the ability to pass
WithRequestEditorFnand other oapi-codegenClientOptionfunctions for HTTP middleware, logging, and request customization.Problem
The functional options refactor (commit 49f57b1) removed the ability to pass
ClientOptionfunctions directly toNew3CommasClient. Users could no longer useWithRequestEditorFnto log or modify HTTP requests before they were sent.Solution
Refactored
ThreeCommasClientto store configuration fields directly on the struct instead of using a separate internalclientConfigtype. This allowsThreeCommasClientOptionto operate on the client itself and enables pass-through of oapi-codegenClientOptionfunctions.Key Changes
ThreeCommasClientstruct:baseURL,apiKey,privatePEM,planTier,httpClient, and newclientOptions []ClientOptionWithClientOption(): Wrapper function that acceptsClientOptionand stores them for pass-throughArchitecture Benefits
This design enables future middleware additions like:
WithLogger(*slog.Logger)for structured loggingWithOpenTelemetry(tracer)for distributed tracingWithMetrics(registry)for observabilityRequestEditorFnfor headers, logging, or request modification