Xsrf middleware for tango
Go to file
Lunny Xiao bf48134bb6
All checks were successful
checks / check and test (push) Successful in 32s
Use actions instead of drone
2023-04-20 15:52:15 +08:00
.gitea/workflows Use actions instead of drone 2023-04-20 15:52:15 +08:00
go.mod use go mod & add drone 2019-06-06 09:57:26 +08:00
go.sum use go mod & add drone 2019-06-06 09:57:26 +08:00
LICENSE license 2015-04-28 16:05:55 +08:00
README.md Use actions instead of drone 2023-04-20 15:52:15 +08:00
xsrf_test.go use go mod & add drone 2019-06-06 09:57:26 +08:00
xsrf.go use go mod & add drone 2019-06-06 09:57:26 +08:00

Xsrf

Middleware xsrf is a xsrf checker for Tango.

Installation

go get gitea.com/tango/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.