<p>There is any tool to analyse the code and detect uncatched errors?</p>
<hr/>**评论:**<br/><br/>usernameliteral: <pre><p><a href="https://github.com/kisielk/errcheck" rel="nofollow">https://github.com/kisielk/errcheck</a></p></pre>diegobernardes: <pre><p>thanks!</p></pre>R2A2: <pre><p>It's an awesome tool. I'd love to use to verify builds, but we'd have to alter our policy on using deferred calls (e.g. 'defer file.Close()') first.</p>
<p>In most cases I'd like to wrap them in a function which logs errors, but I think it's good to contain the use of <code>defer</code> to cases when you really don't need to know the outcome - e.g. 'close' on a file read seems much less important than 'close' while writing a file</p></pre>iqandjoke: <pre><p>I used that tool, but I'm not sure if the below modification is good or not.</p>
<p>Change <code>defer resp.Body.Close()</code> into</p>
<pre><code>defer func() {
if err := resp.Body.Close(); err != nil {
log.Fatal(err)
}
}()
</code></pre>
<p>So which one is better?</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传