engine

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2023 License: MPL-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FormXSRF   = "_xsrf"
	CookieXSRF = "_xsrf"
)

Variables

View Source
var ErrDuplicatedName = errors.New("duplicated form name")

Functions

func New

func New(cfg Config, options ...FormOption) (http.Handler, error)

func XSRF

func XSRF(writer http.ResponseWriter) string

XSRF protection token. Returned token should be submitted as _xsrf form value. Panics if crypto generator is not available.

Types

type AMQPFactory added in v0.3.0

type AMQPFactory interface {
	Create(definition schema.AMQP) notifications.Notification
}

type Config

type Config struct {
	Forms           []schema.Form
	Storage         Storage
	WebhooksFactory WebhooksFactory
	AMQPFactory     AMQPFactory
	Listing         bool
}

type Form

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

func NewForm

func NewForm(config FormConfig, options ...FormOption) *Form

func (*Form) ServeHTTP

func (f *Form) ServeHTTP(writer http.ResponseWriter, request *http.Request)

type FormConfig

type FormConfig struct {
	Definition      schema.Form        // schema definition
	Renderer        *Renderer          // renderer for template blocks
	ViewForm        *template.Template // template to show main form
	ViewResult      *template.Template // template to show result after submit
	Storage         Storage            // where to store data
	WebhooksFactory WebhooksFactory
	AMQPFactory     AMQPFactory
	XSRF            bool // check XSRF token. Disable if form is exposed as API.
}

type FormOption

type FormOption func(config *FormConfig)

func WithXSRF

func WithXSRF(enable bool) FormOption

type Renderer

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

func (*Renderer) Render

func (r *Renderer) Render(value string, req *http.Request, result map[string]any, dataErr error) (string, error)

Render single value as golang template. Caches parsed template.

func (*Renderer) View

func (r *Renderer) View(req *http.Request) *View

type ResultContext

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

func (*ResultContext) Error

func (rc *ResultContext) Error() error

func (*ResultContext) Form

func (rc *ResultContext) Form() schema.Form

func (*ResultContext) Render

func (rc *ResultContext) Render(value string) (string, error)

func (*ResultContext) Result

func (rc *ResultContext) Result() map[string]any

type Storage

type Storage interface {
	Store(ctx context.Context, table string, fields map[string]any) (map[string]any, error)
}

type View

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

func (*View) Render

func (v *View) Render(value string) (string, error)

type ViewContext

type ViewContext struct {
	*View
	XSRF   string
	Form   schema.Form
	Errors []fieldError
}

func (*ViewContext) FieldError

func (vc *ViewContext) FieldError(name string) error

func (*ViewContext) LastValue

func (vc *ViewContext) LastValue(name string) string

func (*ViewContext) LastValues

func (vc *ViewContext) LastValues(name string) utils.Set[string]

type WebhooksFactory added in v0.3.0

type WebhooksFactory interface {
	Create(webhook schema.Webhook) notifications.Notification
}

Jump to

Keyboard shortcuts

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