xsrf

package module
v0.0.0-...-3dbe17f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 26, 2017 License: BSD-3-Clause Imports: 6 Imported by: 5

README

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.

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
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL