Skip to content

Add proper types for context keys#151

Merged
NGTmeaty merged 2 commits into
masterfrom
proper-context-keys
Oct 17, 2025
Merged

Add proper types for context keys#151
NGTmeaty merged 2 commits into
masterfrom
proper-context-keys

Conversation

@CorentinB

Copy link
Copy Markdown
Collaborator

This pull request introduces a new custom context key type to improve type safety and prevent key collisions when storing and retrieving values from Go contexts. The changes update all usages of context keys in the codebase to use the new typed constants instead of raw strings.

Context key improvements:

  • Added a new custom type contextKey and defined constants ContextKeyFeedback and ContextKeyWrappedConn for use as context keys, replacing raw string keys in dialer.go.
  • Updated all context value accesses in dialer.go (wrapConnection and writeWARCFromConnection methods) to use the new typed context key constants instead of string literals. [1] [2]
  • Updated context key usage in the TestHTTPClientWithFeedbackChan test to use ContextKeyFeedback instead of the string "feedback".

@CorentinB CorentinB requested a review from equals215 October 16, 2025 15:36
@CorentinB CorentinB self-assigned this Oct 16, 2025
@CorentinB CorentinB added the enhancement New feature or request label Oct 16, 2025
@CorentinB CorentinB requested a review from NGTmeaty October 16, 2025 15:36
Add WithFeedbackChannel() and WithWrappedConnection() helper functions
to provide a cleaner, more idiomatic API for setting context values.
These helpers improve type safety and developer experience by hiding
the implementation details of context key types.

Changes:
- Add godoc comments to ContextKeyFeedback and ContextKeyWrappedConn
- Add WithFeedbackChannel() helper with usage example
- Add WithWrappedConnection() helper for advanced use cases
- Update README.md example to use the new helper function
- Update test to use WithFeedbackChannel() helper

This makes the API more user-friendly while maintaining the type safety
benefits of using custom context key types (SA1029).

@equals215 equals215 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM
(besides it's not really types but strings wrapped in types and declared as const)

@CorentinB

Copy link
Copy Markdown
Collaborator Author

LGTM (besides it's not really types but strings wrapped in types and declared as const)

regardez moi je suis intelligent

@NGTmeaty NGTmeaty merged commit 33b826c into master Oct 17, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants