我能够做到这一点:
f, err := os.Create("file")
if err != nil {
....
}
by := bufio.NewWriter(f)
而且:
var _ io.Writer = &os.File{}
os.File的软件包文档导致this source file,其中包含未导出的写入函数,但是当我尝试使用未导出的函数实现接口时出现错误。
var _ Disease = &Scratch{} // *Scratch doesn't implement Disease have spread() want Spread()
type Disease interface {
Spread()
}
type Scratch struct {
....
}
func (s* Scratch) spread() {
....
}
我错过了什么?
更新:os.File did need cleaning up
答案 0 :(得分:1)
您错过了Write([]byte)
上*os.File
定义的导出printf
:https://golang.org/src/os/file.go?s=4417:4466#L128