common

package
v0.15.0-dev.17 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeyCore ctxKey = iota
	KeySession
	KeyFrame
	KeyHistoryReplace
)
View Source
const DefaultCacheControl string = "public, max-age=31536000, immutable"

DefaultCacheControl is the Cache-Control value used when ServerCacheControl is empty.

Variables

This section is empty.

Functions

func AsBytes

func AsBytes(s string) []byte

func AsString

func AsString(buf *[]byte) string

func AttrsToMap

func AttrsToMap(a gox.Attrs, logger *slog.Logger) map[string]string

func EncodeId

func EncodeId(b []byte) string

func FreezeDequeBuffer added in v0.13.19

func FreezeDequeBuffer(buffer *deque.Deque[any])

func GetDequeBuffer added in v0.13.19

func GetDequeBuffer() *deque.Deque[any]

func GetGzipWriter added in v0.13.19

func GetGzipWriter(w io.Writer) *gzip.Writer

func InitDefaults

func InitDefaults(s *Conf)

InitDefaults fills zero or invalid values in s with Doors defaults and applies the documented clamps.

func IterTags added in v0.14.0

func IterTags(tag reflect.StructTag) iter.Seq2[string, string]

func Logger added in v0.12.15

func Logger(ctx context.Context) *slog.Logger

func MinifyCSS

func MinifyCSS(input []byte) ([]byte, error)

func NewJsonWriter

func NewJsonWriter(w io.Writer) io.Writer

func PutDequeBuffer added in v0.13.19

func PutDequeBuffer(buffer *deque.Deque[any])

func PutGzipWriter added in v0.13.19

func PutGzipWriter(gz *gzip.Writer)

func RandId

func RandId() string

func ReleaseDequeBuffer added in v0.13.19

func ReleaseDequeBuffer(buffer *deque.Deque[any])

func Zip

func Zip(input []byte) []byte

Types

type CSP

type CSP struct {
	// DefaultSources are the default-src values. Nil emits 'self'; empty
	// omits the directive.
	DefaultSources []string

	// ScriptSources are extra script-src values. The directive is always
	// emitted with 'self', plus the import map hash and the URLs of
	// doors.ResourceExternal scripts when the page has them.
	ScriptSources []string

	// ScriptStrictDynamic adds 'strict-dynamic' to script-src.
	ScriptStrictDynamic bool

	// StyleSources are extra style-src values. The directive is always emitted
	// with 'self', plus the URLs of doors.ResourceExternal stylesheets when the
	// page has them.
	StyleSources []string

	// ConnectSources are extra connect-src values. The directive is always
	// emitted with 'self', which Doors needs for its own requests.
	ConnectSources []string

	// FormActions are the form-action values. Nil emits 'none'; empty omits
	// the directive.
	FormActions []string

	// ObjectSources are the object-src values. Nil emits 'none'; empty omits
	// the directive.
	ObjectSources []string

	// FrameSources are the frame-src values. Nil emits 'none'; empty omits
	// the directive.
	FrameSources []string

	// FrameAncestors are the frame-ancestors values. Nil emits 'none'; empty
	// omits the directive.
	FrameAncestors []string

	// BaseURIAllow are the base-uri values. Nil emits 'none'; empty omits the
	// directive.
	BaseURIAllow []string

	// ImgSources are the img-src values. Nil or empty omits the directive.
	ImgSources []string

	// FontSources are the font-src values. Nil or empty omits the directive.
	FontSources []string

	// MediaSources are the media-src values. Nil or empty omits the directive.
	MediaSources []string

	// Sandbox are the sandbox flags. Nil or empty omits the directive.
	Sandbox []string

	// WorkerSources are the worker-src values. Nil or empty omits the
	// directive.
	WorkerSources []string

	// ReportTo is the report-to group name. Empty omits the directive.
	ReportTo string
}

CSP is the Content-Security-Policy Doors sends on page responses.

func (*CSP) NewCollector

func (c *CSP) NewCollector() CSPCollector

NewCollector returns a collector for one page render. A nil c returns a nil collector.

type CSPCollector

type CSPCollector = *cspCollector

CSPCollector collects the sources and hashes added while one page renders. A nil collector discards them.

func (CSPCollector) Generate

func (c CSPCollector) Generate() string

Generate returns the final Content-Security-Policy header value.

func (CSPCollector) ScriptHash

func (c CSPCollector) ScriptHash(hash []byte)

ScriptHash records an inline script hash for the final header.

func (CSPCollector) ScriptSource

func (c CSPCollector) ScriptSource(source string)

ScriptSource records a script URL for the final header.

func (CSPCollector) StyleHash

func (c CSPCollector) StyleHash(hash []byte)

StyleHash records an inline stylesheet hash for the final header.

func (CSPCollector) StyleSource

func (c CSPCollector) StyleSource(source string)

StyleSource records a stylesheet URL for the final header.

type Conf added in v0.12.1

type Conf struct {
	// SessionInstanceLimit is the max number of live page instances per
	// session. Above it, the least active instance is suspended and reloads
	// on the next interaction. Default: 12.
	SessionInstanceLimit int
	// SessionTTL is how long a session survives its last request. Values at
	// or below InstanceTTL are raised to it.
	SessionTTL time.Duration
	// InstanceConnectTimeout is how long a rendered page has to connect back
	// before its instance is dropped. Default: RequestTimeout.
	InstanceConnectTimeout time.Duration
	// InstanceGoroutineLimit is the max number of goroutines one page
	// instance uses for rendering and reactive work. Default: 8.
	InstanceGoroutineLimit int
	// InstanceTTL is how long an instance is kept without a browser
	// connection before it is dropped. Default: 40m; values below twice
	// RequestTimeout are raised to that.
	InstanceTTL time.Duration
	// ServerCacheControl is the Cache-Control value for managed resources.
	// Default: public, max-age=31536000, immutable.
	ServerCacheControl string
	// ServerDisableGzip disables gzip compression for HTML, Door updates, and
	// managed resources.
	ServerDisableGzip bool
	// ServerSessionCookiePrefix is prepended to the Doors session cookie name.
	// Use it for browser-enforced prefixes such as __Host- or __Secure-.
	ServerSessionCookiePrefix string
	// ServerRequestBodyLimit is the max size in bytes of a hook or form
	// submission request body. Default: 8 MB.
	ServerRequestBodyLimit int
	// ServerSessionCookieNoSecure drops the Secure attribute from the cookies
	// Doors sets. Use it only for plain HTTP development.
	ServerSessionCookieNoSecure bool
	// DisconnectHiddenTimer is how long a hidden page stays connected before it
	// pauses; it reconnects when visible again. Default: InstanceTTL/2.
	DisconnectHiddenTimer time.Duration
	// RequestTimeout is the time limit of one request: page renders on the
	// server, hook and navigation requests in the browser. Default: 30s.
	RequestTimeout time.Duration
	// SolitaireRollTime is how long one live connection request is held open
	// before it is replaced by a fresh one. Lower it behind proxies that cut
	// long requests. Default: 15s.
	SolitaireRollTime time.Duration
	// SolitaireSyncTimeout is how long the server waits for the browser to
	// acknowledge an update before ending the instance. Default: InstanceTTL;
	// larger values are capped at it.
	SolitaireSyncTimeout time.Duration
	// SolitaireFrameTime is how long outgoing updates are batched before they
	// are sent to the browser. Default: 33.3ms.
	SolitaireFrameTime time.Duration
	// SolitaireFrameSize is how many buffered bytes force an immediate send of
	// outgoing updates. Default: 32 KB.
	SolitaireFrameSize int
	// SolitaireDisableGzip disables gzip compression of action payloads sent
	// to the browser.
	SolitaireDisableGzip bool
	// SolitaireQueue is the max number of updates waiting for delivery or
	// acknowledgement. Exceeding it ends the instance. Default: 1024.
	SolitaireQueue int
	// SolitairePending is the max number of delivered but unacknowledged
	// updates; at the limit the server stops sending. Default: 256.
	SolitairePending int
	// SolitaireDisableReportStreaming makes the browser post each message
	// separately instead of streaming one request body. The browser already
	// falls back on its own outside HTTP/2 and HTTP/3.
	SolitaireDisableReportStreaming bool
	// SolitaireReportLimit is the max size in bytes of one message the browser
	// sends back. Default: 8 MB.
	SolitaireReportLimit int
	// SolitaireReportTimeout is how long the server waits to receive one
	// message from the browser before dropping the connection. Default: 5s, or
	// SolitaireRollTime if it is smaller.
	SolitaireReportTimeout time.Duration
	// SolitaireMaxRTT caps the round-trip estimate used to pace waiting on the
	// browser while updates are unacknowledged. Values below twice
	// SolitaireFrameTime are raised to that. Default: 1s.
	SolitaireMaxRTT time.Duration
}

Conf is the Doors runtime configuration.

type EndCause

type EndCause int
const (
	EndCauseKilled EndCause = iota
	EndCauseSuspend
	EndCauseSyncError
)

func (EndCause) Error

func (c EndCause) Error() string

type ID

type ID *id

func NewID

func NewID() ID

type OrderedMap added in v0.12.1

type OrderedMap[K cmp.Ordered, V any] []orderedMapEntry[K, V]

func (*OrderedMap[K, V]) Delete added in v0.12.1

func (s *OrderedMap[K, V]) Delete(k K) bool

func (*OrderedMap[K, V]) Get added in v0.12.1

func (s *OrderedMap[K, V]) Get(k K) (V, bool)

func (OrderedMap[K, V]) Iter added in v0.12.1

func (s OrderedMap[K, V]) Iter() iter.Seq2[K, V]

func (OrderedMap[K, V]) Len added in v0.12.1

func (s OrderedMap[K, V]) Len() int

func (*OrderedMap[K, V]) Set added in v0.12.1

func (s *OrderedMap[K, V]) Set(k K, v V)

type Prime

type Prime = *prime

func NewPrime

func NewPrime() Prime

func (Prime) Gen

func (p Prime) Gen() uint64

type RenderCtx added in v0.15.0

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

func NewRenderCtx added in v0.15.0

func NewRenderCtx(system context.Context, user context.Context) RenderCtx

func (RenderCtx) Deadline added in v0.15.0

func (c RenderCtx) Deadline() (deadline time.Time, ok bool)

func (RenderCtx) Done added in v0.15.0

func (c RenderCtx) Done() <-chan struct{}

func (RenderCtx) Err added in v0.15.0

func (c RenderCtx) Err() error

func (RenderCtx) System added in v0.15.0

func (c RenderCtx) System() context.Context

func (RenderCtx) User added in v0.15.0

func (c RenderCtx) User() context.Context

func (RenderCtx) Value added in v0.15.0

func (c RenderCtx) Value(key any) any

type Set

type Set[T comparable] map[T]struct{}

func NewSet

func NewSet[T comparable]() Set[T]

func (Set[T]) Add

func (s Set[T]) Add(v T) bool

func (Set[T]) Clear

func (s Set[T]) Clear()

func (Set[T]) Has

func (s Set[T]) Has(v T) bool

func (Set[T]) IsEmpty

func (s Set[T]) IsEmpty() bool

func (Set[T]) Iter

func (s Set[T]) Iter() map[T]struct{}

func (Set[T]) Len

func (s Set[T]) Len() int

func (Set[T]) Remove

func (s Set[T]) Remove(v T) bool

func (Set[T]) Slice

func (s Set[T]) Slice() []T

type SolitaireConf

type SolitaireConf struct {
	// Roll is the effective SolitaireRollTime.
	Roll time.Duration
	// FrameSize is the effective SolitaireFrameSize.
	FrameSize int
	// FlushTime is the effective SolitaireFrameTime.
	FlushTime time.Duration
	// DisableGzip is the effective SolitaireDisableGzip.
	DisableGzip bool
	// DisableReportStreaming is the effective SolitaireDisableReportStreaming.
	DisableReportStreaming bool
	// Queue is the effective SolitaireQueue.
	Queue int
	// Pending is the effective SolitairePending.
	Pending int
	// SyncTimeout is the effective SolitaireSyncTimeout.
	SyncTimeout time.Duration
	// ReportSize is the effective SolitaireReportLimit.
	ReportSize int
	// ReportTimeout is the effective SolitaireReportTimeout.
	ReportTimeout time.Duration
	// MaxRTT is the effective SolitaireMaxRTT.
	MaxRTT time.Duration
}

SolitaireConf holds the effective update stream settings taken from Conf.

func GetSolitaireConf

func GetSolitaireConf(s *Conf) *SolitaireConf

GetSolitaireConf returns the effective update stream settings of s.

Jump to

Keyboard shortcuts

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