Adding middleware
Middleware is a piece of code that is configured as an HTTP handler. The middleware will pre-process and post-process the request, and it sits between the main Go server and the actual HTTP handlers that have been declared.
Adding middleware as part of our application helps take care of tasks that are outside of the main application features. Middleware can take care of authentication, logging, and rate limiting, among other things. In the next section, we will look at adding a simple logging middleware.
Basic middleware
In this section, we are going to add a simple basic middleware to our application. The basic middleware is shown in the following code snippet:
func basicMiddleware(h http.Handler) http.Handler { return http.HandlerFunc(func(wr http.ResponseWriter, ...