我能做到:
f, err := os.Create("file")
if err != nil {
....
}
by := bufio.NewWriter(f)
还有这个:
var _ io.Writer = &os.File{}
os.File 的包文档导致 this source file它确实包含一个未导出的写函数,但是当我尝试使用未导出的函数实现接口(interface)时出现错误。
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
最佳答案
您缺少在 *os.File
上定义的导出的 Write([]byte)
:https://golang.org/src/os/file.go?s=4417:4466#L128
关于file - os.File 是如何实现 io.Writer 的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39311307/