O'Reilly logo

Isomorphic Go by Kamesh Balasubramanian

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Registering server-side routes with Gorilla Mux

We will use the Gorilla Mux router to handle the server-side application routing needs. This router is very flexible since it can not only handle simple routes such as /products but it can also handle routes with embedded variables. Recall that the /product-detail route contains the embedded {productTitle} variable.

We will start by creating a new instance of the Gorilla Mux router and assigning it to the r variable as follows:

  r := mux.NewRouter()

Here's the section of code from the registerRoutes function, defined in the igweb.go source file, where we register routes along with their associated handler functions:

r.Handle("/", handlers.IndexHandler(env)).Methods("GET")r.Handle("/index", ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required