【发布时间】:2013-09-11 00:05:42
【问题描述】:
我有两个相关的问题,我不想为这两个问题打开一个新线程:
给定以下代码:
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 }
我们的想法是能够将未知数量的块 key => value、key => key => value 等发送到我们的 API 端点。
问题 1:
如何分配给Request.Values?我们可能需要使用的示例用例如下(请原谅 PHP 代码,我们正在转换):
'name' => [ $first, $last ],
'address' => [ 'city' => 'city', 'state' => 'state' ],
'country' => 'US'
在此示例中,我们有 key => value、key => [ values ] 和 key => [ key => value ]
我怎样才能接受它并将完全相同的值分配给Request.Values?
问题 2:
显然 Values 是 map[string]interface{} 类型,我如何将其转换为类型 io.Reader 以便将值发送到服务器?
非常感谢您对这两个问题的任何指导。
【问题讨论】:
标签: google-app-engine go