Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tigrannajaryan
Copy link
Member

This continues work start in #324 for Client.

The interface has the following downsides:

  • Impossible to define non-trivial default behavior. Here is an example where it was needed: Add CheckRedirect callback #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.

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.
@tigrannajaryan tigrannajaryan requested a review from a team as a code owner December 19, 2024 15:34
Copy link

codecov bot commented Dec 19, 2024

Codecov Report

Attention: Patch coverage is 82.97872% with 8 lines in your changes missing coverage. Please review.

Project coverage is 77.30%. Comparing base (b7beae5) to head (fbfd0ff).

Files with missing lines Patch % Lines
server/serverimpl.go 82.14% 3 Missing and 2 partials ⚠️
server/types/callbacks.go 84.21% 2 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@echlebek echlebek left a 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.

Copy link
Member

@srikanthccv srikanthccv left a comment

Choose a reason for hiding this comment

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

minor doc comments 👍

Comment on lines 42 to 45
// 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.
Copy link
Member

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 {
Copy link
Member

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.

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.

3 participants