Skip to content

Commit a917939

Browse files
committed
Fix passing arrays as query parameters (#1)
1 parent 01224e0 commit a917939

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Documentation of the API can be found at [docs.recombee.com](https://docs.recomb
1010

1111
Run the following command in your Go project:
1212
```
13-
go get github.com/recombee/go-api-client/[email protected].0
13+
go get github.com/recombee/go-api-client/[email protected].1
1414
```
1515

1616
## Examples

recombee/recombee_client.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"net/http"
1717
"net/url"
1818
"strconv"
19+
"strings"
1920
"time"
2021
)
2122

@@ -142,8 +143,14 @@ func (client *RecombeeClient) SendRequestWithContext(ctx context.Context, reques
142143

143144
queryParams := parsedUrl.Query()
144145
for key, value := range request.QueryParameters {
145-
queryParams.Set(key, fmt.Sprintf("%v", value))
146+
switch v := value.(type) {
147+
case []string:
148+
queryParams.Set(key, strings.Join(v, ","))
149+
default:
150+
queryParams.Set(key, fmt.Sprintf("%v", value))
151+
}
146152
}
153+
147154
parsedUrl.RawQuery = queryParams.Encode()
148155
urlWithParams := fmt.Sprintf("/%v%v", client.databaseId, parsedUrl.String())
149156
signedUrl, err := client.signUrlStr(urlWithParams)
@@ -171,7 +178,7 @@ func (client *RecombeeClient) SendRequestWithContext(ctx context.Context, reques
171178

172179
// Set necessary headers
173180
httpRequest.Header.Set("Content-Type", "application/json")
174-
httpRequest.Header.Set("User-Agent", "recombee-go-api-client/4.1.0")
181+
httpRequest.Header.Set("User-Agent", "recombee-go-api-client/4.1.1")
175182

176183
start := time.Now()
177184
// Send the request

0 commit comments

Comments
 (0)