Overriding functions to debug third party packages

agolangf · · 440 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;ve looked for techniques on overriding functions to debug third party packages, but haven&#39;t found any. Here&#39;s the issue I&#39;m up against.</p> <pre><code>package main import github.com/foo/bar baz() </code></pre> <p>I think there&#39;s a bug in baz() (from package bar), so I want to replace it with an instrumented version. I could fork bar on github, make the changes, push, then replace my imports to use my version of baz(), but there&#39;s got to be a better way. Ideas?</p> <hr/>**评论:**<br/><br/>dlsniper: <pre><p>Use delve, <a href="https://github.com/derekparker/delve" rel="nofollow">https://github.com/derekparker/delve</a>, or an editor which properly integrates with it, like Gogland <a href="https://www.jetbrains.com/go/" rel="nofollow">https://www.jetbrains.com/go/</a> </p> <p>You could also vendor the dependency and change it as you need but you&#39;ll need to be careful on how you upgrade it as you could replace it by mistake when you do the upgrade.</p> <p>The loading order of packages since Go 1.6 is:</p> <ul> <li>vendor/</li> <li>GOPATH/</li> <li>GOROOT/</li> </ul> <p>Hope this helps.</p></pre>bobcrotch: <pre><p>Chucking the fork into vendor to debug would be pretty easy. I&#39;ve ended up having to do this a few times and it works with no issue.</p> <p>The biggest pitfall as outline above is working with maintaining either a monkey patched version, or flat out forking it. The worst I&#39;ve seen is a project checking in the vendor dir to put off refactoring. It can lead to a lot of build time headaches if managed poorly and should be generally avoided at all costs.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

440 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传