Skip to content

Commit

Permalink
adds localization (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlicanAkkus committed Jan 2, 2024
1 parent b5b5c8e commit 6752245
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,23 @@ if err != nil {
}
```

Also, you can pass the options to make localization for API responses. You can use `tr` or `en` right now.
```go
client, _ := craftgate.New("<YOUR API KEY>", "<YOUR SECRET KEY>", "https://api.craftgate.io", craftgate.WithLocalization("en"))

request := craftgate.SearchInstallmentsRequest{
BinNumber: "487074",
Price: 100,
Currency: craftgate.Currency_TRY,
}

res, err := client.Installment.SearchInstallments(context.Background(), request)

if err != nil {
t.Errorf("Error %s", err)
}
```

You should use production API servers at `https://api.craftgate.io` for real world. For testing purposes, please use the sandbox URL `https://sandbox-api.craftgate.io`.

## Examples
Expand Down
15 changes: 14 additions & 1 deletion adapter/craftgate.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ func init() {

type ClientOption func(*Client) error

func WithLocalization(lang string) ClientOption {
return func(client *Client) error {
if len(lang) > 0 {
client.headers["lang"] = strings.ToLower(lang)
} else {
client.headers["lang"] = "tr"
}
return nil
}
}

type Client struct {
httpClient *http.Client
baseURL *url.URL
Expand All @@ -90,6 +101,8 @@ type Client struct {

func New(apiKey, apiSecret, baseURL string, opts ...ClientOption) (*Client, error) {
client := newClient(apiKey, apiSecret)
client.headers = make(map[string]string)

for _, option := range opts {
if err := option(client); err != nil {
return nil, err
Expand All @@ -102,7 +115,7 @@ func New(apiKey, apiSecret, baseURL string, opts ...ClientOption) (*Client, erro
if client.baseURL == nil {
client.baseURL, _ = url.Parse(baseURL)
}
client.headers = make(map[string]string)

return client, nil
}

Expand Down

0 comments on commit 6752245

Please sign in to comment.