Skip to content

Commit

Permalink
chore: handle region with switch in client
Browse files Browse the repository at this point in the history
  • Loading branch information
vlnevyhosteny committed Feb 20, 2024
1 parent 95dfb3c commit f77aee6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
18 changes: 12 additions & 6 deletions pkg/celigo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
Expand All @@ -25,17 +26,22 @@ type Client struct {
baseUrl string
}

func New(accessToken string, region Region, httpClient *http.Client) *Client {
baseUrl := BaseUrl
if region == EURegion {
baseUrl = BaseEUUrl
func New(accessToken string, region Region, httpClient *http.Client) (*Client, error) {
var u string
switch region {
case USRegion:
u = BaseUrl
case EURegion:
u = BaseEUUrl
default:
return nil, fmt.Errorf("invalid region: %d", region)
}

return &Client{
httpClient: httpClient,
accessToken: accessToken,
baseUrl: baseUrl,
}
baseUrl: u,
}, nil
}

func (c *Client) newRequestWithDefaultHeaders(ctx context.Context, method string, url *url.URL, body ...interface{}) (*http.Request, error) {
Expand Down
5 changes: 4 additions & 1 deletion pkg/connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ func New(ctx context.Context, accessToken, region string) (*Celigo, error) {
return nil, fmt.Errorf("invalid region: %s", region)
}

client := celigo.New(accessToken, r, httpClient)
client, err := celigo.New(accessToken, r, httpClient)
if err != nil {
return nil, err
}

return &Celigo{
Client: client,
Expand Down

0 comments on commit f77aee6

Please sign in to comment.