Deploying Golang API's. What do?

polaris · · 491 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I was hoping someone here could tell me the best way to deploy golang api&#39;s. I am concerned about a panic during runtime and the server shutting down. </p> <p>Does anyone have some life advise for me?</p> <hr/>**评论:**<br/><br/>deusmetallum: <pre><p>Run it in a docker container with --restart=unless-stopped</p> <p>That way, of the API dies, the docker container will also die, and docker will restart it.</p> <p>If you&#39;re running in Linux, systemd has similar options, but docker is easier and more portable.</p></pre>flamin_flamingo_lips: <pre><p>Ah, great idea. Thank you.</p> <p>I&#39;m imagining having it behind an Apache server too? Forwarding requests to a port.</p></pre>tmornini: <pre><p>Why?</p> <p>But sure, if you want/need to.</p></pre>flamin_flamingo_lips: <pre><p>If we didn&#39;t have a dedicated server for it. So we could run other projects through Apache.</p></pre>tmornini: <pre><p>There are always subdomains...</p></pre>ZetaHunter: <pre><p>Look into using traefik instead of apache then.</p></pre>carsncode: <pre><p>You can always put your process into its own function, and inside main(), use recover to catch any panics and call the function again to re-start it.</p> <p>Note that if this API is using net/http, it already recovers panics and logs them as errors, and the panic only crashes that request, not the whole process.</p></pre>flamin_flamingo_lips: <pre><p>There is some recover magic going on already, but there does seem to be some errors that it can&#39;t recover from fully sometimes. </p> <p>Also I must not be using net/http right in go cause I think anytime it panicked it crashed the server, but I think that may of been from using log.Fatal before. Thanks for your advise though! </p></pre>carsncode: <pre><p>log.Fatal doesn&#39;t panic, it calls os.Exit, which is not recoverable.</p></pre>sprayAtMeBro: <pre><p>If using systemd you could configure it to restart on failure. Docker doesn&#39;t make much sense to me unless that&#39;s already a standard deployment tool for you. </p></pre>AnthonySterling: <pre><p>If it&#39;s just a simple binary, systemd or supervisord would be the way I&#39;d approach this - probably proxied via nginx/apache so I could still have some control over ingress.</p></pre>

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

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