actions

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const ImportPath = "github.com/cssbruno/gowdk/addons/actions"

ImportPath is the canonical Go import path for the actions addon.

Variables

This section is empty.

Functions

func Addon

func Addon() gowdk.Addon

Addon enables typed backend actions and form handling.

func DecodeForm

func DecodeForm(request *http.Request) (form.Values, error)

DecodeForm parses request form data for generated typed action decoders.

func ValidateRequired

func ValidateRequired(values form.Values, fields []string) validation.Result

ValidateRequired records one validation error for each missing required form field. Empty and whitespace-only submitted values are treated as missing.

Types

type CSRF

type CSRF struct {
	// contains filtered or unexported fields
}

CSRF validates signed double-submit CSRF tokens for generated actions.

func NewCSRF

func NewCSRF(options CSRFOptions) (*CSRF, error)

NewCSRF creates a validator with secure cookie defaults.

func (*CSRF) CookieName added in v0.1.5

func (csrf *CSRF) CookieName() string

CookieName returns the cookie name used for CSRF token storage.

func (*CSRF) FieldName added in v0.1.5

func (csrf *CSRF) FieldName() string

FieldName returns the form field name used for submitted CSRF tokens.

func (*CSRF) HeaderName added in v0.1.5

func (csrf *CSRF) HeaderName() string

HeaderName returns the header name used for submitted CSRF tokens.

func (*CSRF) Token

func (csrf *CSRF) Token(response http.ResponseWriter, request *http.Request) (string, error)

Token returns the CSRF token for a generated hidden form field. It reuses the request's valid CSRF cookie when present so concurrently open tabs keep working, and only mints and stores a new token when the cookie is absent or invalid.

func (*CSRF) Validate

func (csrf *CSRF) Validate(request *http.Request) error

Validate checks the submitted token against the CSRF cookie and signature.

type CSRFOptions

type CSRFOptions struct {
	Secret     []byte
	CookieName string
	FieldName  string
	HeaderName string
	Insecure   bool
	SameSite   http.SameSite
}

CSRFOptions configures signed double-submit CSRF tokens.

type CSRFTokenSource added in v0.1.5

type CSRFTokenSource interface {
	Token(http.ResponseWriter, *http.Request) (string, error)
	FieldName() string
}

CSRFTokenSource generates tokens for generated forms.

type CSRFValidator

type CSRFValidator interface {
	Validate(*http.Request) error
}

CSRFValidator validates action requests before generated handlers run.

type Handler

type Handler func(context.Context, form.Values) (response.Response, error)

Handler is a generated typed action endpoint.

type Registry

type Registry map[string]Handler

Registry maps generated action names to handlers.

func (Registry) Register

func (registry Registry) Register(name string, handler Handler)

Register stores one action handler.

Jump to

Keyboard shortcuts

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