Go · lekcja 14 z 30 · Dane, funkcje i wiersz poleceńPołącz pola w strukturę
Struktura trzyma razem slot, model i temperaturę jednego dysku.
14-structs.go Pobierz 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}Ćwiczenie
Wypisz najcieplejszy dysk.
TurboShell nie zawiera Go. Te programy powstają w Bucket & Code, w jego środowisku Go, a gotowy plik działa na NAS-ie bez Go.