Reputation: 585
How can I assign values to a var of type []struct ?
type Mappings []struct {
PropA string
PropB string
}
func main() {
var test Mappings
test = ???
}
Thanks in advance!
Upvotes: 1
Views: 3102
Reputation: 7723
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)
}
Upvotes: 5