Add proper types for context keys#151
Merged
Merged
Conversation
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
approved these changes
Oct 16, 2025
equals215
left a comment
Member
There was a problem hiding this comment.
LGTM
(besides it's not really types but strings wrapped in types and declared as const)
Collaborator
Author
regardez moi je suis intelligent |
NGTmeaty
approved these changes
Oct 17, 2025
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 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:
contextKeyand defined constantsContextKeyFeedbackandContextKeyWrappedConnfor use as context keys, replacing raw string keys indialer.go.dialer.go(wrapConnectionandwriteWARCFromConnectionmethods) to use the new typed context key constants instead of string literals. [1] [2]TestHTTPClientWithFeedbackChantest to useContextKeyFeedbackinstead of the string"feedback".