The alice library reduces the complexity of chaining the middleware when the list of middleware is big. It provides us with a clean API to pass the handler to the middleware. It is a lightweight solution, unlike other middleware chaining Go packages.
Install alice via the go get command, like this:
go get github.com/justinas/alice
Now, we can import the alice package in our program and use it straight away. We can modify the sections of the previous program to bring the same functionality, with improved chaining. Let's call the program directory multipleMiddlewareWithAlice, and create a main program in this location:
touch -p $GOPATH/src/github.com/git-user/chapter3/multipleMiddlewareWithAlice/main.go
In the import section, add github.com/justinas/alice, as shown in the following code snippet:
import (
"encoding/json"
...