csrf

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2024 License: MIT, MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorInvalidToken   = errors.New("invalid csrf token")
	ErrorMissingCookies = errors.New("missing http header cookies")
)

Functions

This section is empty.

Types

type Config

type Config interface{}

func Cache

func Cache(client cache.Client) Config
func Cookie(cookie cookie.Cookie) Config

func Enabled

func Enabled(enabled ...bool) Config

func Expiration

func Expiration(expiration time.Duration) Config

func Request

func Request(request *http.Request) Config

type Csrf

type Csrf interface {
	Exists(name, value string) (bool, error)
	Get(name, value string) (Token, error)
	Create(token Token) (string, error)
	Destroy(token Token) error
	Clean(ignore string) error

	IsEnabled() bool
	GetExpiration() time.Duration

	MustExists(name, value string) bool
	MustGet(name, value string) Token
	MustCreate(token Token) string
	MustDestroy(token Token)
	MustClean(ignore string)
}

func New

func New(configs ...Config) Csrf

type Token

type Token struct {
	Exists    bool   `json:"exists"`
	Name      string `json:"name"`
	Ip        string `json:"ip"`
	UserAgent string `json:"userAgent"`
	Value     string `json:"value"`
}

Jump to

Keyboard shortcuts

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