How to do it...

  1. Install the github.com/gorilla/csrf and github.com/gorilla/mux packages using the go get command, as follows:
$ go get github.com/gorilla/csrf$ go get github.com/gorilla/mux
  1. Create sign-up.html with name and email input text fields and an action that gets called whenever an HTML form is submitted, as follows:
<html>  <head>    <title>Sign Up!</title>  </head>  <body>    <form method="POST" action="/post" accept-charset="UTF-8">      <input type="text" name="name">      <input type="text" name="email">      {{ .csrfField }}      <input type="submit" value="Sign up!">    </form>  </body></html>
  1. Create prevent-csrf.go, where we create a signUp handler that renders a signup HTML form and a post handler that gets executed whenever an HTML form is submitted ...

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.