Structs and Methods

Structs and Methods

Structs are used to group related data. Methods are functions with a receiver type.

type Person struct {
    Name string
    Age int
}

func (p Person) Greet() {
    fmt.Println("Hello, " + p.Name)
}
← PrevNext →