Created
January 13, 2020 19:24
-
-
Save monkrus/83a87ec9616e4466aeb1f11beccd7137 to your computer and use it in GitHub Desktop.
Method in Go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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