README

xsrf Build Status

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.

Documentation

Index

Constants

View Source
const (
	XSRF_TAG string = "_xsrf"
)

Variables

This section is empty.

Functions

func New

func New(timeout time.Duration) tango.HandlerFunc

Types

type Checker

type Checker struct {
	XsrfValue string
	// contains filtered or unexported fields
}

func (*Checker) AutoCheck

func (c *Checker) AutoCheck() bool

func (Checker) CheckXsrf

func (Checker) CheckXsrf() bool

func (*Checker) IsValid

func (c *Checker) IsValid() bool

func (*Checker) Renew

func (c *Checker) Renew()

func (*Checker) SetXsrf

func (c *Checker) SetXsrf(v string, ctx *tango.Context, timeout time.Duration)

func (*Checker) XsrfFormHtml

func (c *Checker) XsrfFormHtml() template.HTML

type NoCheck

type NoCheck struct {
}

func (NoCheck) CheckXsrf

func (NoCheck) CheckXsrf() bool

func (NoCheck) InitXsrfer

func (NoCheck) InitXsrfer(*tango.Context, time.Duration)

type XsrfChecker

type XsrfChecker interface {
	SetXsrf(string, *tango.Context, time.Duration)
	AutoCheck() bool
}

type Xsrfer

type Xsrfer interface {
	CheckXsrf() bool
}

Source Files