allow to use static address for http client
Some checks failed
coverage / build (push) Failing after 0s
test / test (push) Failing after 0s

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2026-02-24 11:55:01 +03:00
parent fe11fb8bcd
commit 39d69bd723
2 changed files with 15 additions and 6 deletions

View File

@@ -48,9 +48,6 @@ func (c *Client) fnCall(ctx context.Context, req client.Request, rsp any, opts .
default: default:
} }
// make copy of call method
hcall := c.call
// use the router passed as a call option, or fallback to the rpc clients router // use the router passed as a call option, or fallback to the rpc clients router
if callOpts.Router == nil { if callOpts.Router == nil {
callOpts.Router = c.opts.Router 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) 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 var routes []string
// lookup the route to send the reques to // lookup the route to send the reques to
// TODO apply any filtering here // 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 // 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 // record the result of the call to inform future routing decisions
if verr := c.opts.Selector.Record(node, err); verr != nil { if verr := c.opts.Selector.Record(node, err); verr != nil {

View File

@@ -146,3 +146,10 @@ func headerFromOpts(opts client.CallOptions) ([]string, bool) {
h, ok := opts.Context.Value(headerKey{}).([]string) h, ok := opts.Context.Value(headerKey{}).([]string)
return h, ok 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)
}