I am writing a backend web api for a mobile app. It should support HTTPS. Most of my experience in .NET, but for this one I want to use Go/Golang. I have a sample service ready, now I need to make sure that it is production ready.
In .NET I will just use IIS, but I have no clue what would be a good approach for Go.
Should I have nginx as reverse proxy, or I better use FastCGI ? And how to make sure that my go app is up and will run on system reboot ? should I use upstart or something similar ?
-
1I've had good results using Nginx on top of a Go API; Nginx takes care of SSL and adding support for SPDY etc is easy. Having Nginx handle deflate/gzip, SSL will also simplify your Go API code.Martin Gallagher– Martin Gallagher2014-11-22 15:07:03 +00:00Commented Nov 22, 2014 at 15:07
-
Do you use nginx as reverse proxy or you run FastCGI ? And how do you keep your go application running ?Tamerlane– Tamerlane2014-11-22 15:14:26 +00:00Commented Nov 22, 2014 at 15:14
-
Nginx as a reverse proxy is da bomb, works great for me as well, with a workload of hundreds of sustained RPSNot_a_Golfer– Not_a_Golfer2014-11-22 15:15:43 +00:00Commented Nov 22, 2014 at 15:15
-
I know it is off topic, but what framework did you guys use ?Tamerlane– Tamerlane2014-11-22 15:26:17 +00:00Commented Nov 22, 2014 at 15:26
-
Reverse proxy as Not_a_Golfer says - personally I'm just using vanilla net/httpMartin Gallagher– Martin Gallagher2014-11-22 15:37:43 +00:00Commented Nov 22, 2014 at 15:37
2 Answers
I've been using Nginx FastCGI with a Go webservice - they work well together. It's no harder to set up than HTTP reverse proxying - except for having to learn how to do it. The performance ought in principle to be a lot better, but I have no measurements to justify that hunch. My web service can work in both HTTP mode and FastCGI mode (one or other at a time), so I suppose I ought to do some benchmarking (note to self!).
If you want proper system startup (and you should), you need to learn how init scripts work. I sometimes cheat and start with an existing working script someone else wrote for a similar application and customise it to work with mine.
Comments
I've used nginx as a reverse proxy for my Go projects. I've found that it's a lot easier to set up useful server settings such as TLS, compression, etc., in nginx rather than as a pure Go server.
Keeping it alive on server reboot is a more complicated question. I would suggest learning how to write a script/whatever for your server's init daemon and just doing it that way.