Tool for merging or concatenating Go source files?

agolangf · · 682 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Does there exist a tool for combining two or more Go source files within a package? I know it seems like a trivial thing to do manually but it would be convenient for the project I&#39;m working on now. It doesn&#39;t seem complicated: just parse the files and combine the ASTs, making sure to remove duplicate package declarations and imports. Thanks.</p> <hr/>**评论:**<br/><br/>dominikh: <pre><p>Russ Cox&#39;s <a href="https://code.google.com/p/rsc/source/browse/cmd/bundle/?r=2ca6bfeb8a439bffe419a94f749f639f04ff6028">bundle</a> utility does that.</p></pre>iamafuckingrobot: <pre><p>Thank you, that did just the trick. Since I want to be able to merge a subset of files within a package, I <a href="https://github.com/naegelejd/gocat" rel="nofollow">modified his tool slightly</a> for my purposes.</p></pre>nuunien: <pre><p>Why do you need to concatenate Go source files? What problem are you trying to solve?</p></pre>iamafuckingrobot: <pre><p>Too many source files, each containing one or two functions and maybe a type.</p></pre>Streamweaver66: <pre><p>Not sure what use this could be but if you only have a few files cat and pipe them for a one time thing. I wonder if Grunt be used for larger sets or more regular merges?</p></pre>davecheney: <pre><p>This will result in multiple package statements per file, a syntax error. </p></pre>Streamweaver66: <pre><p>This is a concern no matter how you merge the code. Easily fixible either with a small post processing script of even a grunt plugin <a href="https://github.com/davidtucker/grunt-line-remover" rel="nofollow">https://github.com/davidtucker/grunt-line-remover</a></p> <p>I still don&#39;t get the use case for doing this at all though so I feel like I&#39;m missing something.</p></pre>iamafuckingrobot: <pre><p>It&#39;s an extremely specific use-case, but for large projects it saves a few minutes. I didn&#39;t really expect the tool to exist but Russ Cox&#39;s <a href="https://code.google.com/p/rsc/source/browse/cmd/bundle/?r=2ca6bfeb8a439bffe419a94f749f639f04ff6028" rel="nofollow">bundle</a> utility (thanks <a href="/u/dominikh" rel="nofollow">/u/dominikh</a>) got me 95% of the way there. See my modified version <a href="https://github.com/naegelejd/gocat" rel="nofollow">here</a></p></pre>Streamweaver66: <pre><p>Well keep us posted on how it goes. Go is so new still that seeing how people are using it is helpful and interesting.</p></pre>earthboundkid: <pre><p>Go works at the folder level, not the file level, so why bother?</p></pre>

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

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