Skip to content

Commit

Permalink
fix default api url not work
Browse files Browse the repository at this point in the history
Signed-off-by: xieydd <xieydd@gmail.com>
  • Loading branch information
xieydd committed Jul 22, 2024
1 parent 06d6284 commit b4f329a
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit b4f329a

Please sign in to comment.