我可能会使用构造函数来做到这一点:
func NewGraph() *Graph { var g Graph g.connections = make(map[Vertex][]Vertex) return &g}我已经在标准
image/jpeg包中找到了这个示例(虽然没有地图,但是有切片):
type Alpha struct { Pix []uint8 Stride int Rect Rectangle}func NewAlpha(r Rectangle) *Alpha { w, h := r.Dx(), r.Dy() pix := make([]uint8, 1*w*h) return &Alpha{pix, 1 * w, r}}


