Skip to content

Instantly share code, notes, and snippets.

@artturijalli
Created March 20, 2021 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artturijalli/2c2aafd1fd46d3381fdbb6654b555d0b to your computer and use it in GitHub Desktop.
Save artturijalli/2c2aafd1fd46d3381fdbb6654b555d0b to your computer and use it in GitHub Desktop.
package main
import "fmt"
// STRUCTURES - a collection of fields to construct a logical type
type Fruit struct {
name string
color string
}
// Create a method for the Fruit that prints info about the fruit
func (fruit Fruit) information(){
fmt.Println("I am a", fruit.color, fruit.name)
}
func main() {
// Create a new Fruit, banana;
banana := Fruit{name:"Banana", color:"Yellow"}
// Use the Fruit method information to print info:
banana.information() // prints "I am a Yellow Banana"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment