Skip to content

Instantly share code, notes, and snippets.

@bcho
Created January 16, 2015 12:28
Show Gist options
  • Select an option

  • Save bcho/dc8f7dfc94378121ff64 to your computer and use it in GitHub Desktop.

Select an option

Save bcho/dc8f7dfc94378121ff64 to your computer and use it in GitHub Desktop.
trick
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