os.File如何实现io.Writer?

时间:2016-09-03 21:03:34

标签: file go writer

我能够做到这一点:

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

1 个答案:

答案 0 :(得分:1)

您错过了Write([]byte)*os.File定义的导出printfhttps://golang.org/src/os/file.go?s=4417:4466#L128