net/http和net/http/fcgi在Golang中的区别

huangapple go评论75阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2013年2月18日 03:17:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/14925005.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定