I have two related questions, I did not want to open a new thread for both questions:
Given the following code:
1 type Request struct {
2 Values map[string]interface{}
3 }
4
5 func (r Request) Send() {
6 client := &http.Client{}
7 resp, _ := http.Post("http://example.com", "text/json", &r.Values)
8 }
The idea is to be able to send a block of an unknown amount key => value
, key => key => value
, etc. to our API endpoint.
Question 1:
How do I assign to Request.Values
? An example use case we may need to employ is the following (Excuse the PHP Code, we're transitioning):
'name' => [ $first, $last ],
'address' => [ 'city' => 'city', 'state' => 'state' ],
'country' => 'US'
In this example we have key => value
, key => [ values ]
, and key => [ key => value ]
How can I take that and assign the exact same values to Request.Values
?
Question 2:
Obviously Values
is of type map[string]interface{}
, how can I convert that to type io.Reader
so I can send the values to the server?
Any guidance is greatly appreciated on both questions.