Go · lesson 14 of 30 · Data, functions and the command lineJoin fields into a struct
A struct keeps the slot, model and temperature of one disk together.
14-structs.go Download 14-structs.go
package main
import "fmt"
type Disk struct {
Slot int
Model string
Temp int
}
func main() {
disks := []Disk{
{Slot: 1, Model: "Example HDD A", Temp: 38},
{Slot: 3, Model: "Example HDD B", Temp: 53},
}
for _, d := range disks {
fmt.Printf("slot %d %s %d C\n", d.Slot, d.Model, d.Temp)
}
disks[0].Temp = 40
fmt.Printf("%+v\n", disks[0])
}
Terminal
$ ./14-structs
slot 1 Example HDD A 38 C
slot 3 Example HDD B 53 C
{Slot:1 Model:Example HDD A Temp:40}Exercise
Print the warmest disk.
TurboShell does not contain Go. These programs are made in Bucket & Code with its Go runtime; the finished file runs on the NAS without Go.