From b4f329a029b3963867fd67300815425d2f0a6f5d Mon Sep 17 00:00:00 2001 From: xieydd Date: Mon, 22 Jul 2024 19:45:30 +0800 Subject: [PATCH] fix default api url not work Signed-off-by: xieydd --- client/client.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/client/client.go b/client/client.go index ed99ada..75002f0 100644 --- a/client/client.go +++ b/client/client.go @@ -37,6 +37,15 @@ func checkApiKey(c *Client) func() error { } } +func checkApiUrl(c *Client) func() error { + return func() error { + if c.apiUrl == "" { + return fmt.Errorf("ApiUrl is required") + } + return nil + } +} + func (client *Client) Clone(opts ...Option) (*Client, error) { clone := func(c Client) *Client { return &c @@ -60,6 +69,7 @@ func (client *Client) Clone(opts ...Option) (*Client, error) { func validate(c *Client) error { checkFns := []func() error{ checkApiKey(c), + checkApiUrl(c), } for _, fn := range checkFns { if err := fn(); err != nil { @@ -136,9 +146,10 @@ func WithDefaultApiUrl() Option { func OverrideApiUrl(apiUrl string) Option { return func(c *Client) { - c.apiUrl = apiUrl + if apiUrl != "" { + c.apiUrl = apiUrl + } } - } func WithDefaultClient() Option {