Go routines with Echo #2205
-
Hello! Just a quick question. Does Echo have a standard implementation on go routines for concurrency? I.E if a user has called my route, does a go routine spawn for the handler of the route? Or Does Echo take a more default approach of just using 1 main go routine (like when running any go program)? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Echo uses standard library http.Server by implementing If you are interested how http.Server serves request I recommend looking at these methods
As Echo instance implements ServeHTTP we can start serving requests like that func main() {
e := echo.New()
// create middlewares and routes here
httpServer := http.Server{
Addr: ":80",
Handler: e, // <-- because Echo implements http.Handler interface
}
if err := httpServer.ListenAndServe(); err != http.ErrServerClosed {
log.Print(fmt.Errorf("error when starting HTTP server: %w", err))
}
} |
Beta Was this translation helpful? Give feedback.
Echo uses standard library http.Server by implementing
http.Handler
interface (here) and does not spawn any goroutines itself. http.Server creates 1 coroutine per incoming connection and in that coroutinehttp.Handler
interface which is in our caseecho.ServeHTTP
function is called and middleware->handler chain starts to be executed.If you are interested how http.Server serves request I recommend looking at these methods