Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between net/http and net/http/fcgi in Golang

Tags:

go

fastcgi

What's the difference? If I use net/http/fcgi package, every request will be executed in new goroutine. It seems to be the same for net/http ListenAndServe...isn't it? What advantages and disadvantages?

like image 211
Tyranron Avatar asked Feb 17 '13 19:02

Tyranron


1 Answers

The net/http/fcgi allows you to listen via the FastCGI protocol for new connections whereas the net/http ListenAndServe is there for listening for incoming http connections. With a FastCGI listener you need an http server sitting in front of the Go process that is proxying incoming connections and sending requests via FastCGI to you Go process.

FastCGi can be useful if you have multiple services that you need to expose on the same port. You can run something like Apache or Nginx as the front end and expose certain urls to your Go process via FastCGI.

If this is not your case and you just want to run a Go web server on a port, stick with net/http.

like image 151
Daniel Avatar answered Sep 22 '22 14:09

Daniel