struct
Basics of Struct
type Product struct {
name string
itemID int
cost float32
isAvailable bool
inventoryLeft int
}Initializing
// define goBook as a Product type
var goBook Product
// assign "Webapps in Go" to the field 'name' of goBook
goBook.name = "Webapps in Go"
// assign 10025 to field 'itemID' of goBook
goBook.itemID = 10025
// access field 'name' of goBook
fmt.Printf("The product's name is %s\n", goBook.name)Embedded fields in struct

Links
Last updated