'Send array in an URL query variable to a server written in Go

I need to send a HTTP request with query to a golang server that uses gendry SQL library. Unfortunately, I don't have exact info about how the server is implemented.

When it comes to a simple query, there is no problem with it:

/api/resource
/api/resource?where={"age >=": 18}
...

However, I need to use limit and offset. For this, there is a _limit property, which should be an array of 2 numbers (offset and limit). There is a part of the library's code:

if val, ok := where["_limit"]; ok {
    arr, ok := val.([]uint) // first is offset, second is limit. 
}

The question is, how can I send an array through URL query string, so it will work? I tried several ways, but each returned an error, eg:

// [builder] the value of "_limit" must be of []uint type
/api/path?where={"_limit": [0, 10]}


Solution 1:[1]

In http, you can specify an array of parameters be repeating the parameter.

/api/path?limit=0&limit=10

Your server should see limit["0","10"]. You can verify this with a simple curl request pointed a postbin such as https://hookbin.com/

curl -X GET "https://hookb.in/<YOUR HOOKBIN ID GOES HERE>?limit=0&limit=10

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sorens