Skip to content

Commit

Permalink
Merge pull request #8 from tensorchord/fix-default-url
Browse files Browse the repository at this point in the history
fix default api url not work
  • Loading branch information
xieydd authored Jul 22, 2024
2 parents 06d6284 + b4f329a commit 2d91f78
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 2d91f78

Please sign in to comment.