<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'm wondering if there's some better known project in the community? I don't want to go too much into esoterics and evaluate everything that I come across, I'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't append them to the binary like the mjl/asset or go.rice which was suggested by @ulfurinn. Doesn't fit my req's, even tho it seems it's a very popular project. I'll keep it in mind if I'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't add much to the build times to be honest.
But I understand if it doesn't fit your needs.</p></pre>serverhorror: <pre><p>Care to explain? What's the difference from the user perspective whether it'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't really see a difference except "implementation detail")</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'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't get any kind of compression benefits. As I'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's a work-around which works for me, but I'm not sure it's all that great/plausible. Added comment on GH. Basically it seems a compressor should be registered with archive/zip package. I'm surprised that it'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'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'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
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传