<p>After a couple of months of on-off Go development, I wonder if I maybe miss something obvious about the Go package documentation.</p>
<p>Say I want to decode a JSON file. The documentation tells me that there is <code>encoding/json.NewDecoder(r io.Reader)</code>. The documentation for <code>io.Reader</code> has no hints about known implementations. Likewise, <code>os.File</code> does not mention that it implements <code>io.Reader</code>. So how, short of reading the interface in its entirety and manually compare it with the functions documented for <code>os.File</code> or just try it and see if the compile blows up, am I supposed to know that I can use a file handle for the JSON decoder? (For that matter, can I? I really can't remember right now :P)</p>
<p>I suppose checking every type against every interface is not feasable for <code>go doc</code>. ;-)</p>
<hr/>**评论:**<br/><br/>cougarpoop: <pre><p>Use the type analyzer of godoc: <a href="https://golang.org/lib/godoc/analysis/help.html">https://golang.org/lib/godoc/analysis/help.html</a></p></pre>mwholt: <pre><p>I did not know about this
Noob question: How to discover interface implementations in the Go documentation?
xuanbao · · 815 次点击这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传