Last active
August 6, 2021 11:38
-
-
Save percybolmer/b4a3ba98ad653feb7b23f25ce388a8cd 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" | |
) | |
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