O'Reilly logo

Go Web Development Cookbook by Arpit Aggarwal

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

How it works…

Once we run the program, the HTTP server will start locally listening on port 8080.

Browsing http://localhost:8080 will show us the same output we saw in our previous recipe, as shown in the following screenshot:

Let's understand the changes we introduced in the main() method as part of this recipe:

  • router :=mux.NewRouter(): Here we instantiated the gorilla/mux router calling the NewRouter() handler of the mux router.
  • router.HandleFunc("/",renderTemplate).Methods("GET"): Here we registered the / URL pattern with the renderTemplate handler. This means renderTemplate will execute for every request with the URL pattern /.
  • router.PathPrefix("/").Handler(http.StripPrefix("/static", ...

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