-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Breaking: Replace Callbacks interface by Callbacks struct (server) #326
base: main
Are you sure you want to change the base?
Breaking: Replace Callbacks interface by Callbacks struct (server) #326
Conversation
This continues work start in open-telemetry#324 for Client. The interface has the following downsides: - Impossible to define non-trivial default behavior. Here is an example where it was needed: open-telemetry#269 (comment) - Adding new callbacks requires expanding the interface, which is a breaking change for existing client users. Getting rid of the interface and keeping just a struct for callbacks solves both problems: - Arbitrarily complex default behavior can be now defined on the struct if the user does not provide the particular callback func. - Adding new callback funcs is not a braking change, existing users won't be affected.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #326 +/- ##
==========================================
+ Coverage 77.29% 77.30% +0.01%
==========================================
Files 25 25
Lines 2281 2274 -7
==========================================
- Hits 1763 1758 -5
+ Misses 410 408 -2
Partials 108 108 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. The change is removing a level of nesting from a lot of places in the codebase too. 👍
I do see a minor possible improvement, defaults could be defined as free standing functions and set by name in SetDefaults
, which would avoid the possibility of closing over function vars by accident. But, that's really a tiny nit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor doc comments 👍
// ConnectionCallbacks receives callbacks for a specific connection. An implementation of | ||
// this interface MUST be set on the ConnectionResponse returned by the OnConnecting | ||
// callback if Accept=true. The implementation can be shared by all connections or can be | ||
// unique for each connection. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change the wording here because it still refers to "interface" and "implementation" here?
@@ -15,7 +15,7 @@ type ConnectionResponse struct { | |||
ConnectionCallbacks ConnectionCallbacks | |||
} | |||
|
|||
type Callbacks interface { | |||
type Callbacks struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
ConnectionCallbacks MUST be set to an implementation of the ConnectionCallbacks interface to handle the connection.
This continues work start in #324 for Client.
The interface has the following downsides:
Getting rid of the interface and keeping just a struct for callbacks solves both problems: