I'm a PHP developer new to Golang. PHP comes with an inbuilt server which is not recommended for production. I read the beautiful book by astaxie on web development in Go and also the golang.org example on writing a web app. They both use the http.ListenAndServe()
to create a web server. I just want to know if this server can be used in production or is it just a dummy server like PHP inbuilt server? By production I mean, can it handle huge traffic like an Apache or ngnix server?
Short answer: YES.
Server provides Shutdown method for graceful shutdown. Run a server and send a request to /shutdown , then the server stops.
The main function of a HTTP server is to store, process and deliver web pages to clients. Pages delivered are usually HTML documents, which may include images, style sheets and scripts in addition to text content.
Short answer: YES.
Longer answer: you can certainly use the built in Web server for production traffic. There's a good chance you've used it today, since Google serves some traffic using it. I know a lot of companies, including the one I work for that use it for production traffic. BTW I don't know of a Web server widely used in Go that does not use the standard web server.
Keep in mind though that you need to tweak things like client timeouts to make it really robust, and perhaps limit incoming connections, etc.
To add to @Not_a_Golfer's answer: Go's web-server is extremely solid and pretty well tested thus far.
There are, however, reasons why you might put it behind a reverse proxy like nginx, Apache or HAProxy, including:
I generally prefer to put nginx in front if I have the option, because although you can implement all of those features in Go, there's a bit of wheel re-invention going on. You can get most of the way there with middleware like gorilla/handlers and Go's own crypto/tls lib, and if you're not an ops person and/or want to keep things really thin, then running everything directly from Go is still fine for production.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With