title: Golang echo package middleware implementation
body: <p>I'm learning Go and was going through this example : <a href="https://echo.labstack.com/cookbook/middleware" rel="nofollow noreferrer">echo middleware example</a>. I wanted to do a deep dive to understand what was going on when we call <code>next(c)</code> in the function middleware function <code>Process()</code>. </p>
  
  <p>Looking at the <code>main()</code> I understand we append the <code>Process()</code> function to the echo <code>Context</code> object's list of middleware functions via the <code>Use()</code> call. However, looking at the <a href="https://github.com/labstack/echo/blob/master/echo.go" rel="nofollow noreferrer">echo source code</a> I'm unsure how the <code>next(c)</code> call in the <code>Process()</code> function in the middleware example looks through all of the context's middleware functions. Couple things that I cannot seem to find even after searching the source code:</p>
  
  <p>(1) Where is the function definition for <code>echo.HandlerFunc</code> being defined? I see <a href="https://github.com/labstack/echo/blob/master/echo.go#L761" rel="nofollow noreferrer">WrapHandler</a> but that's exported and not used in <code>echo.go</code> so I'm confused what happens when <code>next(c)</code> gets called what line of code in <code>echo.go</code> source code we jump to. </p>
  
  <p>(2) It looks like the loop happens when calling <code>applyMiddleware</code> as that seems to loop through all the middleware functions saved in the Context's list of middleware functions but I don't see how that method is called unless you call the exported <code>WrapMiddleware</code> function or <code>ServeHTTP</code> etc.</p>