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

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