Newb here, I was wondering if there was a way to "go get" inside a compiled program.

agolangf · · 648 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I already use package <code>os/exec</code> to <code>get</code> the package I need every time the program is run but I guess that once the &#34;main&#34; file is compiled, all of it&#39;s dependancies compile into the binary as well. Is there someway to tell the computer to ignore <code>lib/package</code> and compile it every time the bianary is run?</p> <hr/>**评论:**<br/><br/>Fwippy: <pre><p>Why?</p></pre>theDamnKid: <pre><p>It&#39;s for an application for operation nunya.</p> <p>as in nunya business.</p> <hr/> <p>Now that I got my shitty snarky remark out of the way, I am making a &#34;ban&#34; list for people if they abuse a system on a server. I want to update that list without having to reinstall the program every time.</p></pre>djherbis: <pre><p>You shouldn&#39;t need to recompile to update a blacklist. You should use a database, or hot reloading config file for updates like that.</p></pre>kurin: <pre><p>This is an XY problem if I&#39;ve ever seen one. Jeez.</p></pre>Fwippy: <pre><p>Yeah, I&#39;m glad I asked.</p></pre>Shammyhealz: <pre><p>Just to add on to what djherbis said, you don&#39;t want to compile this in because it&#39;s going to get loaded into memory. Hence as the block list grows, so does your memory footprint. People could potentially abuse the system again by just creating a ton of accounts, abusing the system, and getting banned until your memory footprint is too large for the server. This is basically going to create a denial of service vector where there doesn&#39;t need to be one.</p> <p>Databases are really want you want for this. Go for SQLite if you don&#39;t want to run a separate daemon process, it should be plenty fast enough unless you&#39;re banning tons and tons of people.</p> <p>All that being said, if you&#39;re still determined to do it, just write this as a service and write the re-compile step into your init script. Or wrap the binary in a script that does the re-compile.</p></pre>theDamnKid: <pre><p>It&#39;s on a linux server of about 150 people. I <strong>might</strong> ban 10. They can&#39;t make more accounts so there&#39;s that... but sure. thanks for the help.</p></pre>Fwippy: <pre><p>Yeah, I&#39;d probably just go with a <code>blacklist.txt</code> file - have your program read that file to get the list of users to block every time it starts up, so all you have to do is edit that one file.</p></pre>Malangelus: <pre><blockquote> <p>It&#39;s for an application for operation nunya.</p> <p>as in nunya business.</p> <hr/> <p>Now that I got my shitty snarky remark out of the way, I am making a &#34;ban&#34; list for people if they abuse a system on a server. I want to update that list without having to reinstall the program every time.</p> </blockquote> <p>What a dickish response to a reasonable question. Your approach is dumb by the way; you shouldn&#39;t be recompiling a static hardcoded list for a ban list, that&#39;s idiotic. Use a text file or a DB.</p></pre>vruzz: <pre><p>You can&#39;t easily self-modify the binary you&#39;re running (and it&#39;s probably not even possible to mess with in Go during runtime). One approach would be to keep a small launcher that compiles, executes, and does all the juggling.<br/> Or maybe use readily-existing code to simplify updates <a href="https://github.com/sanbornm/go-selfupdate" rel="nofollow">https://github.com/sanbornm/go-selfupdate</a></p> <p>Another approach would be to generate and use dynamically linked libraries, this is a new feature in Go 1.5 <a href="https://golang.org/doc/go1.5" rel="nofollow">https://golang.org/doc/go1.5</a></p> <p>Take a look here: <a href="http://www.darkcoding.net/software/building-shared-libraries-in-go-part-1/" rel="nofollow">http://www.darkcoding.net/software/building-shared-libraries-in-go-part-1/</a></p></pre>

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

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