Last active
August 6, 2021 11:37
-
-
Save percybolmer/d1f03d7662e2ba2b01aa81e1e4ff8244 to your computer and use it in GitHub Desktop.
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 Human struct { | |
Name string | |
} | |
// This is our method receiver, the type Human receives the Hello method | |
func (h Human) Hello() string { | |
return fmt.Sprintf("Hello, %s!", h.Name) | |
} | |
func main() { | |
h := Human{ | |
Name: "Bob", | |
} | |
// Since human has received the method Hello, we can call it | |
fmt.Println(h.Hello()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment