Asynchronous Processing with jQuery in the Go Revel Framework
Overview
We’ll implement asynchronous Ajax processing in the Go Revel framework.
CSRF Protection
Install the library for CSRF protection in the Revel framework with the following command:
1 | $ go get github.com/cbonello/revel-csrf |
- app/init.go
To run the CSRF check at Ajax execution time, configure init.go so that the check is disabled there.

init.go
GitHub Gist: instantly share code, notes, and snippets.
The CSRF filter configuration is shown below.
1 | func init() |
Since the API URL invoked in conf/routes is checked for CSRF at Ajax execution time,
configure init.go to exclude it from the check.
1 | csrf.ExemptedFullPath("/api_execute") |
View-side Configuration
- views/header.html
Embed the hash value for the CSRF check as meta information inside <head>〜</head>.
1 | <meta name="csrf-token" content="{{ .csrf_token }}"> |
jQuery File
1 | function setAjaxToken( token ) { |
It may not have been quite as simple as I’d hoped, but
we’ve got CSRF protection in place.
