December 2017
Intermediate to advanced
316 pages
6h 58m
English
Gorilla Mux allows us to create a new router, similar to httprouter. But the attachment of the handler function to a given URL route is different in both. If we observe, Mux's way of attaching a handler is similar to that of basic ServeMux. Unlike httprouter, it modifies the request object instead of using an additional argument to pass the URL parameters to the handler function. We can access parameters using the Vars method.
I am going to take an example from the Gorilla Mux homepage to explain how useful it is. Create a file called muxRouter.go and add the following code:
package mainimport ( "fmt" "log" "net/http" "time" "github.com/gorilla/mux")// ArticleHandler is a function handlerfunc ArticleHandler(w ...