From 5f8338cd3685cee14033d552ff3319ac74cc5c43 Mon Sep 17 00:00:00 2001 From: presbrey Date: Tue, 3 Sep 2024 17:24:28 -0400 Subject: [PATCH] api: add Client.BaseURL method --- api/client.go | 7 +++++++ api/client_test.go | 3 +++ 2 files changed, 10 insertions(+) diff --git a/api/client.go b/api/client.go index 2528fb21..15aa2394 100644 --- a/api/client.go +++ b/api/client.go @@ -378,3 +378,10 @@ func (c *Client) Version(ctx context.Context) (string, error) { return version.Version, nil } + +// BaseURL returns the base URL of the client. +func (c *Client) BaseURL() *url.URL { + // make a copy of the base URL to prevent mutation + base := *c.base + return &base +} diff --git a/api/client_test.go b/api/client_test.go index 23fe9334..9ad7ec59 100644 --- a/api/client_test.go +++ b/api/client_test.go @@ -40,6 +40,9 @@ func TestClientFromEnvironment(t *testing.T) { if client.base.String() != v.expect { t.Fatalf("expected %s, got %s", v.expect, client.base.String()) } + if client.BaseURL().String() != v.expect { + t.Fatalf("expected %s, got %s", v.expect, client.BaseURL().String()) + } }) } }