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
| type speaker interface { | |
| speak() string | |
| } | |
| type cat struct{} | |
| func (c *cat) speak() string { return "Miau!" } | |
| type dog struct{} |
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
| type myError struct{} | |
| func (m *myError) Error() string { | |
| return "failure" | |
| } | |
| func doSomething() (string, error) { | |
| return "", nil | |
| } |
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
| type myError struct{} | |
| func (m *myError) Error() string { | |
| return "failure" | |
| } | |
| func doSomething() (string, *myError) { | |
| return "", nil | |
| } |
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
| func doToast(t toaster) { | |
| t.toast() | |
| } |
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
| type toaster interface { | |
| toast() | |
| } | |
| type acmeToaster struct {} | |
| func (a *acmeToaster) toast() { fmt.Println("Commencing toasting of bread...") } |
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
| type monster struct { | |
| damage int | |
| } | |
| func (m *monster) attack() int { | |
| return m.damage | |
| } | |
| type attacker interface { | |
| attack() int |
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
| type empty interface {} |
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
| // Verify that acmeToaster satisfies interface toaster. | |
| var _ toaster = &acmeToaster{} |
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
| type toaster interface { | |
| toast() | |
| } | |
| type acmeToaster struct {} | |
| func (a *acmeToaster) toast() { fmt.Println("Commencing toasting of bread...") } | |
| func doToast(t toaster) { | |
| t.toast() |
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
| type Vehicle interface { | |
| Start() | |
| Stop() | |
| } | |
| type Car struct {} | |
| func (c *Car) Start() { | |
| fmt.Println("starting engine...") | |
| } |