Skip to content

Instantly share code, notes, and snippets.

@monkrus
Created January 13, 2020 19:24
Show Gist options
  • Select an option

  • Save monkrus/83a87ec9616e4466aeb1f11beccd7137 to your computer and use it in GitHub Desktop.

Select an option

Save monkrus/83a87ec9616e4466aeb1f11beccd7137 to your computer and use it in GitHub Desktop.
Method in Go
package main
import (
"fmt"
)
type person struct {
first string
last string
}
type secretAgent struct {
person
ltk bool
}
// func (r receiver, attaches function to this type) ientifier(parameters) (return(s)) {code}
func (s secretAgent) speak() {
fmt.Println("I am", s.first, s.last)
}
func main() {
sa1 := secretAgent{
person: person{
"James",
"Bond",
},
ltk: true,
}
fmt.Println(sa1)
sa1.speak()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment