Deprecate client/selector (#1767)

* client/{grpc,rpc}: depricate selector (wip)

* {client,cmd}: remove client/selector

* deprecate client/selector

* router/static: fix lookup

* config/cmd: add support for legacy static selector flag

* config/cmd: add support for legacy dns selector flag
This commit is contained in:
ben-toogood
2020-07-01 17:06:59 +01:00
committed by GitHub
parent a63480a81a
commit 174e44b846
46 changed files with 428 additions and 1572 deletions

View File

@@ -4,34 +4,35 @@ import (
"errors"
"net/http"
"github.com/micro/go-micro/v2/client/selector"
"github.com/micro/go-micro/v2/router"
"github.com/micro/go-micro/v2/selector"
)
type roundTripper struct {
rt http.RoundTripper
st selector.Strategy
st selector.Selector
opts Options
}
func (r *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
s, err := r.opts.Registry.GetService(req.URL.Host)
routes, err := r.opts.Router.Lookup(router.QueryService(req.URL.Host))
if err != nil {
return nil, err
}
next := r.st(s)
// rudimentary retry 3 times
for i := 0; i < 3; i++ {
n, err := next()
route, err := r.st.Select(routes)
if err != nil {
continue
}
req.URL.Host = n.Address
req.URL.Host = route.Address
w, err := r.rt.RoundTrip(req)
if err != nil {
continue
}
return w, nil
}