From b8d2c5dd23a2b185f3869bd01a6f3f5fbdec3691 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Wed, 1 Jul 2020 17:06:59 +0100 Subject: [PATCH] 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 --- rpc.go | 19 +++++-------------- stream.go | 8 +++++--- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/rpc.go b/rpc.go index 49fc430..7e8790c 100644 --- a/rpc.go +++ b/rpc.go @@ -12,16 +12,15 @@ import ( jsonpatch "github.com/evanphx/json-patch/v5" "github.com/micro/go-micro/v2/api" "github.com/micro/go-micro/v2/api/handler" + "github.com/micro/go-micro/v2/api/handler/util" "github.com/micro/go-micro/v2/api/internal/proto" "github.com/micro/go-micro/v2/client" - "github.com/micro/go-micro/v2/client/selector" "github.com/micro/go-micro/v2/codec" "github.com/micro/go-micro/v2/codec/jsonrpc" "github.com/micro/go-micro/v2/codec/protorpc" "github.com/micro/go-micro/v2/errors" "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/metadata" - "github.com/micro/go-micro/v2/registry" "github.com/micro/go-micro/v2/util/ctx" "github.com/micro/go-micro/v2/util/qson" "github.com/oxtoacart/bpool" @@ -65,14 +64,6 @@ func (b *buffer) Write(_ []byte) (int, error) { return 0, nil } -// strategy is a hack for selection -func strategy(services []*registry.Service) selector.Strategy { - return func(_ []*registry.Service) selector.Next { - // ignore input to this function, use services above - return selector.Random(services) - } -} - func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { bsize := handler.DefaultMaxRecvSize if h.opts.MaxRecvSize > 0 { @@ -141,8 +132,8 @@ func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } - // create strategy - so := selector.WithStrategy(strategy(service.Services)) + // create custom router + callOpt := client.WithRouter(util.Router(service.Services)) // walk the standard call path // get payload @@ -174,7 +165,7 @@ func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { ) // make the call - if err := c.Call(cx, req, response, client.WithSelectOption(so)); err != nil { + if err := c.Call(cx, req, response, callOpt); err != nil { writeError(w, r, err) return } @@ -209,7 +200,7 @@ func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { client.WithContentType(ct), ) // make the call - if err := c.Call(cx, req, &response, client.WithSelectOption(so)); err != nil { + if err := c.Call(cx, req, &response, callOpt); err != nil { writeError(w, r, err) return } diff --git a/stream.go b/stream.go index 5f0b10a..b51d59d 100644 --- a/stream.go +++ b/stream.go @@ -13,8 +13,8 @@ import ( "github.com/gobwas/ws" "github.com/gobwas/ws/wsutil" "github.com/micro/go-micro/v2/api" + "github.com/micro/go-micro/v2/api/handler/util" "github.com/micro/go-micro/v2/client" - "github.com/micro/go-micro/v2/client/selector" raw "github.com/micro/go-micro/v2/codec/bytes" "github.com/micro/go-micro/v2/logger" ) @@ -110,9 +110,11 @@ func serveWebsocket(ctx context.Context, w http.ResponseWriter, r *http.Request, client.StreamingRequest(), ) - so := selector.WithStrategy(strategy(service.Services)) + // create custom router + callOpt := client.WithRouter(util.Router(service.Services)) + // create a new stream - stream, err := c.Stream(ctx, req, client.WithSelectOption(so)) + stream, err := c.Stream(ctx, req, callOpt) if err != nil { if logger.V(logger.ErrorLevel, logger.DefaultLogger) { logger.Error(err)