Adding assets into go binaries

blov · · 378 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>What do you use if you want to include assets inside the build binary? For example, I have a assets/ folder which I would zip/tar and would like to append it to the go binary, and use it from there if possible. I found mjl/asset (<a href="https://www.ueber.net/who/mjl/blog/p/assets-in-go-binaries/" rel="nofollow">https://www.ueber.net/who/mjl/blog/p/assets-in-go-binaries/</a>) which seems to be similar to what I want, but I&#39;m wondering if there&#39;s some better known project in the community? I don&#39;t want to go too much into esoterics and evaluate everything that I come across, I&#39;d rather be pointed to something which is accepted by the community :) Thank you!</p> <hr/>**评论:**<br/><br/>Sphax: <pre><p><a href="https://github.com/jteeuwen/go-bindata" rel="nofollow">go-bindata</a> is used a lot for this. I used it for a project, it works well.</p></pre>titpetric: <pre><p>From what I can read about it, it compiles assets into go code, and doesn&#39;t append them to the binary like the mjl/asset or go.rice which was suggested by @ulfurinn. Doesn&#39;t fit my req&#39;s, even tho it seems it&#39;s a very popular project. I&#39;ll keep it in mind if I&#39;m ever fine with extending build times for this stuff :)</p></pre>Sphax: <pre><p>Yeah it embeds the assets into the code. I use it with a lot of html/css/js and it doesn&#39;t add much to the build times to be honest. But I understand if it doesn&#39;t fit your needs.</p></pre>serverhorror: <pre><p>Care to explain? What&#39;s the difference from the user perspective whether it&#39;s appended or has some other method? No matter what the package needs to expose/generate some kind of APU to access the stuff. What am I missing in here? (Not trying to make an argument for one method over another, I just don&#39;t really see a difference except &#34;implementation detail&#34;)</p></pre>titpetric: <pre><p>From the user (as in the person who runs the app), none. From my side, I can burn in user specific configs (like client id, user specific assets,...) without having to compile go code on the fly. Basically, this is a simpler process to deliver basically the same thing. Well, no, you can also unzip the binary this way, giving a simpler way to inspect asset contents in comparison, if that would ever be important.</p></pre>scheldkultur: <pre><p>I use this one too, it works perfectly for my use case.</p></pre>ulfurinn: <pre><p>I&#39;m quite fond of <a href="https://github.com/GeertJohan/go.rice" rel="nofollow">rice</a>.</p></pre>titpetric: <pre><p>Unfortunately, it seems the appended data doesn&#39;t get any kind of compression benefits. As I&#39;m not sure this is by design I submitted an issue on the GH repo <a href="https://github.com/GeertJohan/go.rice/issues/84" rel="nofollow">https://github.com/GeertJohan/go.rice/issues/84</a> </p> <p>Edit: there&#39;s a work-around which works for me, but I&#39;m not sure it&#39;s all that great/plausible. Added comment on GH. Basically it seems a compressor should be registered with archive/zip package. I&#39;m surprised that it&#39;s possible to omit compression in zip files tbh.</p></pre>ChristophBerger: <pre><p><a href="https://github.com/jteeuwen/go-bindata" rel="nofollow">go-bindata</a></p> <p>Edit: The same but with filesystem API for HTTP FileServer: <a href="https://github.com/elazarl/go-bindata-assetfs" rel="nofollow">go-bindata-assets</a></p></pre>sh41: <pre><p>I&#39;ve tried to collect all the similar solutions in this space here:</p> <p><a href="https://github.com/shurcooL/vfsgen#comparison" rel="nofollow">https://github.com/shurcooL/vfsgen#comparison</a></p></pre>go255: <pre><p>Late to the party but there&#39;s always the <a href="https://github.com/avelino/awesome-go#resource-embedding" rel="nofollow">Awesome Go</a> list with somewhat popular libraries and stuff.</p></pre>SaturnsVoid: <pre><p>Could store it as a base64 string and decode and save it on request</p></pre>

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

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