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

Struct and type

  • type
  • struct
package main

import (
	"fmt"
)

type aPerson struct {
	id       int
	name     string
	shoeSize float32
	children []string
}

func main() {
	joe := aPerson{
		id:       1,
		name:     "Joe",
		shoeSize: 42.5,
		children: []string{"Alpha", "Beta"},
	}
	fmt.Println(joe)
	fmt.Println()

	fmt.Println(joe.id)
	fmt.Println(joe.name)
	fmt.Println(joe.shoeSize)
	fmt.Println(joe.children)
	fmt.Println(joe.children[0])
}
{1 Joe 42.5 [Alpha Beta]}

1
Joe
42.5
[Alpha Beta]
Alpha