I want to know how exactly goroutine and go web server works whenever requests come in:
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
In this code,
Every request to
/
calls thehandler
. Does this mean each request spawns its own goroutine? Or does it spawns its ownprocess
orthread
? Is there any documentation on how those requests get its own goroutine?How do other languages handle this request? For example, does Python flask launch its own process for each request?
Thanks,