Skip to content

Instantly share code, notes, and snippets.

View mkock's full-sized avatar
💭
Currently building stuff in Go and Vue.js

Martin Kock mkock

💭
Currently building stuff in Go and Vue.js
View GitHub Profile
type speaker interface {
speak() string
}
type cat struct{}
func (c *cat) speak() string { return "Miau!" }
type dog struct{}
type myError struct{}
func (m *myError) Error() string {
return "failure"
}
func doSomething() (string, error) {
return "", nil
}
type myError struct{}
func (m *myError) Error() string {
return "failure"
}
func doSomething() (string, *myError) {
return "", nil
}
func doToast(t toaster) {
t.toast()
}
type toaster interface {
toast()
}
type acmeToaster struct {}
func (a *acmeToaster) toast() { fmt.Println("Commencing toasting of bread...") }
type monster struct {
damage int
}
func (m *monster) attack() int {
return m.damage
}
type attacker interface {
attack() int
type empty interface {}
// Verify that acmeToaster satisfies interface toaster.
var _ toaster = &acmeToaster{}
type toaster interface {
toast()
}
type acmeToaster struct {}
func (a *acmeToaster) toast() { fmt.Println("Commencing toasting of bread...") }
func doToast(t toaster) {
t.toast()
type Vehicle interface {
Start()
Stop()
}
type Car struct {}
func (c *Car) Start() {
fmt.Println("starting engine...")
}