【问题标题】:Declare array of struct literal声明结构字面量数组
【发布时间】:2014-09-24 16:01:29
【问题描述】:

如何声明结构字面量数组?

去:

type Ping struct {
    Content []aContent
}

type aContent struct {
    Type        string
    Id          string
    Created_at  int64
}

func main() {
    f := Ping{Content: []aContent{Type: "Hello", Id: "asdf"}}
    fmt.Println(f)
}

代码可以在这里找到:http://play.golang.org/p/-SyRw6dDUm

【问题讨论】:

    标签: go


    【解决方案1】:

    您只需要另一副牙套。

    []aContent{{Type: "Hello", Id: "asdf"}, {Type: "World", Id: "ghij"}}}
               ^                                                      ^
             here                                                    and here
    

    这是数组的一对,数组中的每个结构都有一个..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-19
      • 1970-01-01
      • 2020-11-09
      • 1970-01-01
      • 1970-01-01
      • 2013-06-19
      • 2018-05-13
      • 1970-01-01
      相关资源
      最近更新 更多