Learn the basics of using and applying middleware.
- The standard library has much of what you need to build services and apps.
- The http package provides the building blocks.
- There are other great packages in the Go ecosystem to help.
https://golang.org/pkg/net/http/
https://golang.org/doc/articles/wiki/
github.com/urfave/negroni
github.com/justinas/alice
github.com/gorilla/handlers
Basic middleware: Code | Test
Negroni router: Code | Test
Alice with Gorilla Handlers: Code
Passing data with context: Code | Test
Take the Negroni code from example 2 and extend the code by adding a new middleware handler to validate authentication. This call must happen before processing anything else. If authentication fails return a 500 and cancel the processing of the request. If authentication succeeds finish processing the rest of the handlers. Use a query string to cause authentication to succeed or fail.
All material is licensed under the Apache License Version 2.0, January 2004.