-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
[suggestion] Make ProxyBalancer interface Next() method return error as well #2313
Comments
We can not change interfaces as it would be breaking change. I suggest ugly workaround. We introduce new Line 235 in 8f2bf82
And for your balancer - return specific It is ugly but this does not break backwards compatibility |
or create additional interface with single method something like that var tgt *ProxyTarget
ntBalancer, ok := config.Balancer.(interface {
NextTarget(echo.Context) (*ProxyTarget, error)
})
if ok {
tgt, err = ntBalancer.NextTarget(c)
if err != nil {
return err
}
} else {
tgt = config.Balancer.Next(c)
} |
Thanks for your input, If I understand correctly you suggest to create closure function to the default handler which will set the |
Would that break existing codebases if added to the echo? |
ntBalancer, ok := config.Balancer.(interface {
NextTarget(echo.Context) (*ProxyTarget, error)
}) would not be a breaking change as it does not touch existing interfaces and it is just additional check if we implement (some new anonymous interface) and then act on it. Add something like that to near line 225 ntBalancer, isImplementingNextTarget := config.Balancer.(interface {
NextTarget(echo.Context) (*ProxyTarget, error)
}) and replace line tgt := config.Balancer.Next(c) with var tgt *ProxyTarget
if isImplementingNextTarget {
tgt, err = ntBalancer.NextTarget(c)
if err != nil {
return err
}
} else {
tgt = config.Balancer.Next(c)
} NB: I have not tested this code if it really work. but seems to compile |
Resolved in this |
Use case:
Currently I need to forward request from my server to another ones. Unfortunatly I can not know in advance their urls (as suggested in documentation) as I need to make some calculations based on provided path and other rules.
What I did:
I created custom struct that satisfies ProxyBalancer interface
It works great but if I encounter error during the selection of next ProxyTarget it can't report the error and I need to panic, thus I would like to change the ProxyBalancer interface from:
to
The interface is used only in proxy.go, so the change IMO wont hurt.
If the change makes sense I could provide the necessary changes in PR.
Thanks in advance for your time.
The text was updated successfully, but these errors were encountered: