Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Slice of structs

package main

import (
	"fmt"
)

type aPerson struct {
	name  string
	email string
}

func main() {
	joe := aPerson{
		name:  "Joe",
		email: "joe@joehome.com",
	}

	jane := aPerson{
		name:  "Jane",
		email: "jane@janehome.com",
	}

	people := []aPerson{}
	fmt.Println(people)

	people = append(people, joe, jane)
	fmt.Println(people)
}
[]
[{Joe joe@joehome.com} {Jane jane@janehome.com}]