I can not find a mod_go for deploying Go web applications. Is there any other way to run web applications in Go with an Apache web server (or even IIS)?
Update: Now after doing Go full time for nearly a year; doing this (Go with Apache) is nullifying the very purpose of Go (Performance in terms of being highly concurrent). And I'm using nginx as a reverse proxy for http/https and having my Go backends behind it nicely. Though you have to change your mindset on webapps a bit when using Go.
Creating a golang web application, using go modules and the gin web framework to serve strings, JSON, and static files. Using a multistage Dockerfile to create a lightweight Docker image. Deploying a Docker-based application to Heroku using heroku stack:set container and a heroku. yml file.
There's no mod_go. (At least I've not heard of such a thing.)
A go web app by itself is a capable web server. You can listen to port 80 in your app and then directly run it on your server. Trust me: it really works!
But if you are not doing that (for reasons such as having other virtual servers on the same machine, load balancing, etc.), you can use a HTTP server such as nginx or Apache as a HTTP proxy in front of your Go app. I use nginx and it's great. Here's an outdated but still very useful guide on how to do that with nginx. I haven't done it with Apache, but this should help.
I recommend your Go web app by itself or nginx as a HTTP proxy.
In addition to the other options, there's also the net/http/fcgi package. This is similar to the CGI option, but it uses FastCGI and your application can keep state if it needs to.
Here's the FastCGI version of jimt's example. Note that only two lines are different. Depending on how you configure Apache, you may have to change the first argument to something different, but nil is the common case.
package main import ( "fmt" "net/http" "net/http/fcgi" ) func hello(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello from Go!") } func main() { http.HandleFunc("/", hello) fcgi.Serve(nil, nil) }
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