actions

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

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) Token

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

Token generates a CSRF token, stores it in a cookie, and returns the value for a generated hidden form field.

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 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 NoopCSRF

type NoopCSRF struct{}

NoopCSRF is for tests only.

func (NoopCSRF) Validate

func (NoopCSRF) Validate(*http.Request) error

Validate accepts every request.

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