Deploying Golang API's. What do?

polaris · 2017-08-12 10:00:09 · 649 次点击    
这是一个分享于 2017-08-12 10:00:09 的资源,其中的信息可能已经有所发展或是发生改变。

I was hoping someone here could tell me the best way to deploy golang api's. I am concerned about a panic during runtime and the server shutting down.

Does anyone have some life advise for me?


评论:

deusmetallum:

Run it in a docker container with --restart=unless-stopped

That way, of the API dies, the docker container will also die, and docker will restart it.

If you're running in Linux, systemd has similar options, but docker is easier and more portable.

flamin_flamingo_lips:

Ah, great idea. Thank you.

I'm imagining having it behind an Apache server too? Forwarding requests to a port.

tmornini:

Why?

But sure, if you want/need to.

flamin_flamingo_lips:

If we didn't have a dedicated server for it. So we could run other projects through Apache.

tmornini:

There are always subdomains...

ZetaHunter:

Look into using traefik instead of apache then.

carsncode:

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.

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.

flamin_flamingo_lips:

There is some recover magic going on already, but there does seem to be some errors that it can't recover from fully sometimes.

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!

carsncode:

log.Fatal doesn't panic, it calls os.Exit, which is not recoverable.

sprayAtMeBro:

If using systemd you could configure it to restart on failure. Docker doesn't make much sense to me unless that's already a standard deployment tool for you.

AnthonySterling:

If it's just a simple binary, systemd or supervisord would be the way I'd approach this - probably proxied via nginx/apache so I could still have some control over ingress.


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

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