Skip to content

Instantly share code, notes, and snippets.

@PeteGabriel
Last active August 15, 2018 17:02
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 PeteGabriel/cd77c5446e7d6e5ea874b0d9ac34066a to your computer and use it in GitHub Desktop.
Save PeteGabriel/cd77c5446e7d6e5ea874b0d9ac34066a to your computer and use it in GitHub Desktop.
Example of method calls in GO
package main
import (
"fmt"
)
func main() {
//Declare a pointer of type Human
peter := new(Human)
//The compile will dereference the pointer to make the call
peter.sayHello()
}
//custom defined interface
type Person interface {
sayHello()
}
//custom defined type
type Human struct {}
//Human type implements Person interface
func (p *Human) sayHello() { fmt.Println("Hello") }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment