How to do it...

  1. Install github.com/gorilla/mux and github.com/gorilla/securecookie using the go get command, as follows:
$ go get github.com/gorilla/mux$ go get github.com/gorilla/securecookie
  1. Create home.html inside the templates directory, as follows:
$ mkdir templates && cd templates && touch home.html
  1. Copy the following content to home.html:
<html>  <head>    <title></title>  </head>  <body>    <h1>Welcome {{.userName}}!</h1>    <form method="post" action="/logout">      <button type="submit">Logout</button>    </form>  </body></html>

In the preceding template, we defined a placeholder, {{.userName}}, whose values will be substituted by the template engine at runtime and a Logout button. By clicking the Logout button, the client will make a POST call ...

Get Go Web Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.