小编眭文峰*_*眭文峰的帖子

can golang function return interface{}{} - 如何返回地图列表

func getLatestTxs() map[string]interface{}{} {
    fmt.Println("hello")
    resp, err := http.Get("http://api.etherscan.io/api?module=account&action=txlist&address=0x266ac31358d773af8278f625c4d4a35648953341&startblock=0&endblock=99999999&sort=asc&apikey=5UUVIZV5581ENPXKYWAUDGQTHI956A56MU")
    defer resp.Body.Close()
    body, _ := ioutil.ReadAll(resp.Body)
    if err != nil {
        fmt.Errorf("etherscan????")
    }
    ret := map[string]interface{}{}
    json.Unmarshal(body, &ret)
    if ret["status"] == 1 {
        return ret["result"]
    }
}
Run Code Online (Sandbox Code Playgroud)

我想map[string]interface{}{}在我的代码中返回。

但我有编译错误 syntax error: unexpected [ after top level declaration

如果我更改map[string]interface{}{}interface{},则不再有编译错误。

我使用的注意力map[string]interface{}{}是因为我想返回一个地图列表。

interface go go-map

5
推荐指数
1
解决办法
7596
查看次数

标签 统计

go ×1

go-map ×1

interface ×1