Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Last active August 6, 2021 11:38
Show Gist options
  • Save percybolmer/b4a3ba98ad653feb7b23f25ce388a8cd to your computer and use it in GitHub Desktop.
Save percybolmer/b4a3ba98ad653feb7b23f25ce388a8cd to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
func main() {
user := &User{
Name: "Brandon",
Email: "Sandersson",
}
Print(user)
}
// Print accepts any printer and runs their Print function
func Print(p Printer) {
p.Print()
// uncomment p.Rewind to see whats wrong with this
// p.Rewind()
}
type Printer interface {
Print()
Rewind()
}
type User struct {
Name string
Email string
Printer
}
func (u *User) Print() {
fmt.Println("User: ", u.Name)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment