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 myError struct{}
func (m *myError) Error() string {
return "failure"
}
func doSomething() (string, error) {
return "", nil
}
type speaker interface {
speak() string
}
type cat struct{}
func (c *cat) speak() string { return "Miau!" }
type dog struct{}
type player struct {
// unexported fields
}
func (p *player) status() string {
return "Player is eating"
}
func (p *player) sleep() {
// implementation goes here
type sword struct {}
func (s *sword) status() string {
return "Sword is damaged"
}
type equippable interface{
equip()
unequip()
}
type meleeWeapon interface {
equippable // Embeds equippable
slash()
}
type car struct {}
func (c *car) start() { return }
func (c *car) stop() { return }
type vehicle interface {
start()
stop()
}
type car struct {}
func (c *car) start() { return }
func (c *car) stop() { return }
func (c *car) recycle() { fmt.Println("Recycling...") }
type vehicle interface {
start()
stop()
}
type car struct {}
func (c *car) start() { return }
func (c *car) stop() { return }
func (c *car) recycle() { return }
func (c *car) convertToBatMobile() { fmt.Println("I am now a BatMobile!") }
type vehicle interface {
start()
stop()
type movie string
func (m movie) Movie() string { return string(m) }
type movieStar string
func (m movieStar) Star() string { return string(m) }
func movieOrStar(m interface{}) string {
switch v := m.(type) {
type persona interface {
strength() int
intelligence() int
stamina() int
}
type dwarf struct {}
func (d *dwarf) strength() int { return 80 }
func (d *dwarf) intelligence() int { return 55 }
func (d *dwarf) stamina() int { return 90 }