Skip to content
This repository was archived by the owner on Mar 21, 2019. It is now read-only.

tango-contrib/xsrf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

3dbe17f · May 26, 2017

History

20 Commits
Apr 28, 2015
Apr 22, 2017
May 26, 2017
Jul 7, 2015
Apr 28, 2015

Repository files navigation

xsrf CircleCI

Middleware xsrf is a xsrf checker for Tango.

Installation

go get github.com/tango-contrib/xsrf

Simple Example

type XsrfAction struct {
    render.Render
    xsrf.Checker
}

func (x *XsrfAction) Get() error {
    return x.Render("test.html", render.T{
        "XsrfFormHtml": x.XsrfFormHtml(),
    })
}

func (x *XsrfAction) Post() {
    // xsrf will be checked before this being called
}

func main() {
    t := tango.Classic()
    t.Use(xsrf.New(expireTime))
    t.Run()
}

If you don't want some action do not check, then

type NoCheckAction struct {
    xsrf.NoCheck
}

func (x *NoCheckAction) Post() {
    // xsrf will NOT be checked before this being called
}

will be ok.

License

This project is under BSD License. See the LICENSE file for the full license text.