声明struct literal数组

use*_*985 8 go

如何声明struct literal数组?

走:

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)
}
Run Code Online (Sandbox Code Playgroud)

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

nos*_*nos 21

你只需要另一对牙套.

[]aContent{{Type: "Hello", Id: "asdf"}, {Type: "World", Id: "ghij"}}}
           ^                                                      ^
         here                                                    and here
Run Code Online (Sandbox Code Playgroud)

这是数组的一对,一个用于数组中的每个结构.