Go: Struct and method
A short, tested Go example for struct and method. Copy it and adjust the names and paths for your project.
Go
type User struct {
Name string
Age int
}
func (u User) Greet() string {
return "Hi, " + u.Name
}
u := User{Name: "Ann", Age: 31}
fmt.Println(u.Greet())Find it in Zest
Search for “go struct and method” in Zest and this example appears above the results, with other matches to choose from. Searches stay private.