慕莱坞森
例如,简洁地最小化内存分配和使用,package mainimport "fmt"type Foo struct { A string B string}type Bar struct { C string D Baz}type Baz struct { E string F string}func FooFromBar(bs []Bar) []Foo { fs := make([]Foo, 0, len(bs)) for _, b := range bs { fs = append(fs, Foo{ A: b.C, B: b.D.E, }) } return fs}func main() { b := []Bar{{C: "C", D: Baz{E: "E", F: "F"}}} fmt.Println(b) f := FooFromBar(b) fmt.Println(f)}输出:[{C {E F}}][{C E}]