在go(golang)中为切片结构赋值

时间:2017-07-04 18:12:11

标签: go

如何为var [type struct]

赋值
type Mappings []struct {
    PropA       string  
    PropB       string 
}

func main() {
    var test Mappings
    test = ???
}

提前致谢!

1 个答案:

答案 0 :(得分:3)

package main

import (
    "fmt"
)
type Mappings []struct {
    PropA       string  
    PropB       string 
}

func main() {
    var test Mappings
    test = Mappings{
        {PropA: "foo", PropB: "bar"},
        {PropA: "bar", PropB: "baz"},
    }
    fmt.Println(test)
}