사용자가 URL에 도달했을 때 응답을 제공하기 위해 http.ListenAndServe
을 사용하는 경우 함수의 해당 동작을 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에서 실행된다는 것을 기억하면됩니다. –