doupinwan0563 2016-09-03 21:03
浏览 130
已采纳

os.File如何实现io.Writer?

I'm able to do this:

f, err := os.Create("file")
if err != nil {
    ....
}
by := bufio.NewWriter(f)

And this:

var _ io.Writer = &os.File{}

The package documentation for os.File leads to this source file which does contain an unexported write function but I get an error when I try to implement an interface with an unexported function.

var _ Disease = &Scratch{}  // *Scratch doesn't implement Disease have spread() want Spread()
type Disease interface {
    Spread()
}
type Scratch struct {
    ....
}
func (s* Scratch) spread() {
    ....
}

What am I missing ?

Update: os.File did need cleaning up

  • 写回答

1条回答 默认 最新

  • dongpi9494 2016-09-03 21:09
    关注

    You are missing the exported Write([]byte) defined on *os.File here: https://golang.org/src/os/file.go?s=4417:4466#L128

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!