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 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 ...

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