Skip to content

feat: restore request editor capability via WithClientOption#7

Merged
terwey merged 2 commits intomainfrom
claude/restore-request-editor-fn-011CV2QYeF5wZtra8Zp61JA9
Nov 11, 2025
Merged

feat: restore request editor capability via WithClientOption#7
terwey merged 2 commits intomainfrom
claude/restore-request-editor-fn-011CV2QYeF5wZtra8Zp61JA9

Conversation

@terwey
Copy link
Copy Markdown
Collaborator

@terwey terwey commented Nov 11, 2025

Summary

Restores the ability to pass WithRequestEditorFn and other oapi-codegen ClientOption functions for HTTP middleware, logging, and request customization.

Problem

The functional options refactor (commit 49f57b1) removed the ability to pass ClientOption functions directly to New3CommasClient. Users could no longer use WithRequestEditorFn to log or modify HTTP requests before they were sent.

Solution

Refactored ThreeCommasClient to store configuration fields directly on the struct instead of using a separate internal clientConfig type. This allows ThreeCommasClientOption to operate on the client itself and enables pass-through of oapi-codegen ClientOption functions.

Key Changes

  • Moved config fields to ThreeCommasClient struct: baseURL, apiKey, privatePEM, planTier, httpClient, and new clientOptions []ClientOption
  • Added WithClientOption(): Wrapper function that accepts ClientOption and stores them for pass-through
  • Request editor ordering: User-provided request editors execute before the RSA authentication signer, enabling proper logging of requests before signing

Architecture Benefits

This design enables future middleware additions like:

  • WithLogger(*slog.Logger) for structured logging
  • WithOpenTelemetry(tracer) for distributed tracing
  • WithMetrics(registry) for observability
  • Any custom RequestEditorFn for headers, logging, or request modification

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.
@terwey terwey merged commit ed9323a into main Nov 11, 2025
1 check passed
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.

2 participants