Created
January 16, 2015 12:28
-
-
Save bcho/dc8f7dfc94378121ff64 to your computer and use it in GitHub Desktop.
trick
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" | |
| "os" | |
| ) | |
| type MyFile struct { | |
| MyField string | |
| *os.File | |
| } | |
| func (f *MyFile) Foo() string { | |
| return f.MyField + f.Name() | |
| } | |
| func main() { | |
| f, _ := os.Open("./test.go") | |
| // Initialize embedded type. | |
| file := MyFile{"foo", f} | |
| fmt.Printf("%s", file.Foo()) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment