Skip to content

Commit

Permalink
update the struct of the query parameter in the custom request method
Browse files Browse the repository at this point in the history
  • Loading branch information
zakhar-petukhov committed Dec 10, 2024
1 parent 30b63c4 commit 55f0bc5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
8 changes: 5 additions & 3 deletions tonapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (c *Client) GetAccountState(ctx context.Context, accountID tongo.AccountID)

// Request sends an HTTP request with the given method, URL, parameters, and data,
// and returns the response as a json.RawMessage.
func (c *Client) Request(ctx context.Context, method, endpoint string, query map[string]string, data []byte) (json.RawMessage, error) {
func (c *Client) Request(ctx context.Context, method, endpoint string, query map[string][]string, data []byte) (json.RawMessage, error) {
const contentType = "application/json"

// Start measuring the request duration
Expand All @@ -84,8 +84,10 @@ func (c *Client) Request(ctx context.Context, method, endpoint string, query map
// Add query parameters to the URL if any
if query != nil {
q := u.Query()
for key, value := range query {
q.Set(key, value)
for key, values := range query {
for _, value := range values {
q.Add(key, value)
}
}
u.RawQuery = q.Encode()
}
Expand Down
11 changes: 9 additions & 2 deletions tonapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestCustomRequest(t *testing.T) {
name string
method string
path string
query map[string]string
query map[string][]string
err error
}{
{
Expand Down Expand Up @@ -55,7 +55,14 @@ func TestCustomRequest(t *testing.T) {
name: "ok to get collections",
method: http.MethodGet,
path: "v2/nfts/collections",
query: map[string]string{"limit": "10"},
query: map[string][]string{"limit": {"10"}},
err: nil,
},
{
name: "ok to exec get method",
method: http.MethodGet,
path: "v2/blockchain/accounts/EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs/methods/get_wallet_address",
query: map[string][]string{"args": {"UQDNzlh0XSZdb5_Qrlx5QjyZHVAO74v5oMeVVrtF_5Vt1rIt", "UQBVXzBT4lcTA3S7gxrg4hnl5fnsDKj4oNEzNp09aQxkwmCa"}},
err: nil,
},
}
Expand Down

0 comments on commit 55f0bc5

Please sign in to comment.