Go 如何在结构中使用嵌套数组?

Go 如何在结构中使用嵌套数组?,go,Go,我的结构如下: type InputData struct { fullname string `bson:"fullname"` parts []string `bson:"parts"` alt string `bson:"alt"` } 现在我想使用这个结构。但是我怎样才能添加部件呢? 我的意思是: myvar := InputData{fullname:"

我的结构如下:

    type InputData struct {
        fullname string `bson:"fullname"`
        parts []string `bson:"parts"`
        alt string `bson:"alt"`
    }
现在我想使用这个结构。但是我怎样才能添加部件呢? 我的意思是:

myvar := InputData{fullname:"Sample", parts: ["A", "B", "C"], alt: "Something"}

谢谢

您需要创建一个字符串片段。 例如:


注意:代码中没有数组<代码>[]字符串是一个切片。
myvar := InputData{fullname:"Sample", parts: []string{"A", "B", "C"}, alt: "Something"}