Skip to content

Instantly share code, notes, and snippets.

@jochasinga
Last active August 29, 2015 14:07
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 jochasinga/7074b122780558e154d1 to your computer and use it in GitHub Desktop.
Save jochasinga/7074b122780558e154d1 to your computer and use it in GitHub Desktop.
Basic method calling before implementing interfaces
package main
import "fmt"
type Man struct {
language string
// other factors to decide if the girl would like you (for fun)
name, nationality, build, eye_color string
age, height uint8
// you could be in debt, so we can't rule out negative values
income int64
// this is to remind her you are available
married bool
}
func (m Man) Greet() {
switch m.language {
case "British" : fmt.Println("Good morning, dear")
case "American": fmt.Println("Mornin' there")
case "Japanese": fmt.Println("Ohayou Gozaimasu")
case "Thai" : fmt.Println("Arunsawad Krub")
default : fmt.Println("Good morning")
}
}
func main() {
jay := new(Man) // just leave other fields to 0
jay.language = "Japanese"
jay.Greet() // print "Ohayou Gozaimasu"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment