From 39d69bd723400b623e96fefb107105bf0618ca21 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Tue, 24 Feb 2026 11:55:01 +0300 Subject: [PATCH] allow to use static address for http client Signed-off-by: Vasiliy Tolstov --- client_unary_call.go | 14 ++++++++------ options.go | 7 +++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/client_unary_call.go b/client_unary_call.go index de3391a..15badee 100644 --- a/client_unary_call.go +++ b/client_unary_call.go @@ -48,9 +48,6 @@ func (c *Client) fnCall(ctx context.Context, req client.Request, rsp any, opts . default: } - // make copy of call method - hcall := c.call - // use the router passed as a call option, or fallback to the rpc clients router if callOpts.Router == nil { callOpts.Router = c.opts.Router @@ -80,7 +77,10 @@ func (c *Client) fnCall(ctx context.Context, req client.Request, rsp any, opts . time.Sleep(t) } - if next == nil { + var node string + if addr, ok := c.opts.Context.Value(addressKey{}).(string); ok && addr != "" { + node = addr + } else if next == nil { var routes []string // lookup the route to send the reques to // TODO apply any filtering here @@ -96,10 +96,12 @@ func (c *Client) fnCall(ctx context.Context, req client.Request, rsp any, opts . } } - node := next() + if node == "" { + node = next() + } // make the call - err = hcall(ctx, node, req, rsp, callOpts) + err = c.call(ctx, node, req, rsp, callOpts) // record the result of the call to inform future routing decisions if verr := c.opts.Selector.Record(node, err); verr != nil { diff --git a/options.go b/options.go index c0dd465..a250fce 100644 --- a/options.go +++ b/options.go @@ -146,3 +146,10 @@ func headerFromOpts(opts client.CallOptions) ([]string, bool) { h, ok := opts.Context.Value(headerKey{}).([]string) return h, ok } + +type addressKey struct{} + +// Address specifies http endpoint address to connect, that will be used as prefix for path +func Address(s string) client.Option { + return client.SetOption(addressKey{}, s) +}