I Spy Code - GO

Struct type

Go langs structs are typed collections of fields.

A struct is a sequence of named elements, called fields, each of which has a name and a type. Field names may be specified explicitly (IdentifierList) or implicitly (AnonymousField). Within a struct, non-blank field names must be unique.

Here is a go lang example that shows how to use a struct.

Source: (example.go)

package main
 
import "fmt"
 
type person struct {
    name string
    age  int
}
 
func main() {
 
   tom := person{name: "Tom", age: 50}
 
   fmt.Println(tom)
   fmt.Println(tom.name)
   fmt.Println(tom.age)
}
 

Output:

$ go run example.go
{Tom 50}
Tom
50