英文:
Difference between net/http and net/http/fcgi in Golang
问题
如果我使用net/http/fcgi包,每个请求都将在新的goroutine中执行。对于net/http ListenAndServe也是一样的,不是吗?有什么优缺点?
英文:
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?
答案1
得分: 15
net/http/fcgi
允许您通过FastCGI协议监听新连接,而net/http
的ListenAndServe用于监听传入的HTTP连接。使用FastCGI监听器,您需要在Go进程前面放置一个HTTP服务器,该服务器代理传入的连接并通过FastCGI将请求发送到您的Go进程。
如果您有多个需要在同一端口上公开的服务,FastCGI可能会很有用。您可以运行像Apache或Nginx这样的前端,并通过FastCGI将某些URL公开给您的Go进程。
如果这不是您的情况,而您只想在端口上运行一个Go Web服务器,请使用net/http
。
英文:
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
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论