GoLang简单的REST API应该使用GoRoutines

我的问题很简单.

我应该将GoRoutines用于一个非常简单的REST API吗?

我基本上只对数据库进行简单查询,验证会话或进行登录.这些操作是否值得设置GoRoutine? GoRoutines何时有用,我该如何设置它们?

net / Http包已经为您解决了这个问题.一旦你调用Serve(或更可能是ListenAndServe),就会发生以下情况:

Serve accepts incoming HTTP connections on the listener l,creating a new service goroutine for each. The service goroutines read requests and then call handler to reply to them. Handler is typically nil,in which case the DefaultServeMux is used.

有关更多信息,请参见http://golang.org/pkg/net/http/

如果请求触发需要更长时间的处理并且您不想让客户端等待,您可能需要另一个goroutine.

相关文章

什么是Go的接口? 接口可以说是一种类型,可以粗略的理解为他...
1、Golang指针 在介绍Golang指针隐式间接引用前,先简单说下...
1、概述 1.1 Protocol buffers定义 Protocol buffe...
判断文件是否存在,需要用到"os"包中的两个函数: os.Stat(...
1、编译环境 OS :Loongnix-Server Linux release 8.3 CPU指...
1、概述 Golang是一种强类型语言,虽然在代码中经常看到i:=1...