0
如果我使用http.ListenAndServe
在用户点击URL时提供响应,我是否应该将函数中的相应操作作为goroutine来触发?我应该使用http.ListenAndServe使用goroutines吗?
例如,说我在听/
:
func main() {
http.HandleFunc("/", provideMainContent)
}
func provideMainContent(w http.ResponseWriter, r *http.Request) {
/// Bunch of code, looks up details in databases, parses, then returns
}
应的代码provideMainContent
这帮在goroutine中被包裹,因此不会减慢事后说来任何潜在的请求?
ListenAndServe()方法为你做,我们不必处理,只记得每个处理程序运行在不同的goroutine –