common

package
v0.15.0-dev.9 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 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"

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.

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 {
	// default-src:
	//   nil          ⇒ emit:   default-src 'self'
	//   len == 0     ⇒ omit:   (no default-src directive)
	//   len > 0      ⇒ emit:   default-src <values>
	DefaultSources []string

	// script-src (user additions only):
	//   Directive is ALWAYS emitted with at least 'self' plus any collected hashes/sources.
	//   nil or len == 0 ⇒ no extra user sources added.
	ScriptSources []string

	// script-src strict-dynamic:
	//   When true, appends 'strict-dynamic' to script-src (typically used with nonces/hashes).
	ScriptStrictDynamic bool

	// style-src (user additions only):
	//   Directive is ALWAYS emitted with at least 'self' plus any collected hashes/sources.
	//   nil or len == 0 ⇒ no extra user sources added.
	StyleSources []string

	// connect-src (user additions only):
	//   Directive is ALWAYS emitted with at least 'self'.
	//   nil or len == 0 ⇒ results in: connect-src 'self'
	//   len > 0         ⇒ connect-src 'self' <values>
	ConnectSources []string

	// form-action:
	//   nil      ⇒ emit:   form-action 'none'
	//   len == 0 ⇒ omit:   (no form-action directive)
	//   len > 0  ⇒ emit:   form-action <values>
	FormActions []string

	// object-src:
	//   nil      ⇒ emit:   object-src 'none'
	//   len == 0 ⇒ omit:   (no object-src directive)
	//   len > 0  ⇒ emit:   object-src <values>
	ObjectSources []string

	// frame-src:
	//   nil      ⇒ emit:   frame-src 'none'
	//   len == 0 ⇒ omit:   (no frame-src directive)
	//   len > 0  ⇒ emit:   frame-src <values>
	FrameSources []string

	// frame-ancestors:
	//   nil      ⇒ emit:   frame-ancestors 'none'
	//   len == 0 ⇒ omit:   (no frame-ancestors directive)
	//   len > 0  ⇒ emit:   frame-ancestors <values>
	FrameAncestors []string

	// base-uri:
	//   nil      ⇒ emit:   base-uri 'none'
	//   len == 0 ⇒ omit:   (no base-uri directive)
	//   len > 0  ⇒ emit:   base-uri <values>
	BaseURIAllow []string

	// img-src:
	//   nil or len == 0 ⇒ omit
	//   len > 0         ⇒ emit: img-src <values>
	ImgSources []string

	// font-src:
	//   nil or len == 0 ⇒ omit
	//   len > 0         ⇒ emit: font-src <values>
	FontSources []string

	// media-src:
	//   nil or len == 0 ⇒ omit
	//   len > 0         ⇒ emit: media-src <values>
	MediaSources []string

	// sandbox:
	//   nil or len == 0 ⇒ omit
	//   len > 0         ⇒ emit: sandbox <flags>
	Sandbox []string

	// worker-src:
	//   nil or len == 0 ⇒ omit
	//   len > 0         ⇒ emit: worker-src <values>
	WorkerSources []string

	// report-to:
	//   ""  ⇒ omit
	//   set ⇒ emit: report-to <value>
	// NOTE: To make this effective, you must also send a corresponding
	//       `Report-To` HTTP response header that defines the reporting group.
	ReportTo string
}

CSP configures the Content-Security-Policy header generated by Doors.

Nil and empty slices have different meanings for several directives, as noted on each field.

func (*CSP) NewCollector

func (c *CSP) NewCollector() CSPCollector

NewCollector creates a per-response collector for c.

type CSPCollector

type CSPCollector = *cspCollector

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 CSP header.

func (CSPCollector) ScriptSource

func (c CSPCollector) ScriptSource(source string)

ScriptSource records a dynamic script source for the final CSP header.

func (CSPCollector) StyleHash

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

StyleHash records an inline stylesheet hash for the final CSP header.

func (CSPCollector) StyleSource

func (c CSPCollector) StyleSource(source string)

StyleSource records a dynamic stylesheet source for the final CSP header.

type Conf added in v0.12.1

type Conf struct {
	// SessionInstanceLimit is the max number of page instances per session.
	// When exceeded, the oldest inactive ones are suspended.
	// Default: 12.
	SessionInstanceLimit int
	// SessionTTL controls how long session lives after last activity.
	// Default behavior (value 0): InstanceTTL
	SessionTTL time.Duration
	// InstanceConnectTimeout controls how long new instance waits
	// before shutdown for the first client connection.
	// Default: RequestTimeout
	InstanceConnectTimeout time.Duration
	// InstanceGoroutineLimit is the max goroutines per page instance.
	// Controls resource use for rendering and reactive updates. Default: 8.
	InstanceGoroutineLimit int
	// InstanceTTL is how long an inactive instance is kept before cleanup.
	// Active = browser connected. Default: 40minutes.
	InstanceTTL time.Duration
	// ServerCacheControl defines cache control header value for JS and CSS
	// resources prepared by the framework.
	// Default "public, max-age=31536000, immutable"
	ServerCacheControl string
	// ServerDisableGzip disables gzip compression for HTML, JS, and CSS if true.
	ServerDisableGzip bool
	// ServerSessionCookiePrefix sets the internal Doors session cookie name prefix.
	// Use it when you want browser-enforced cookie prefix rules, such as
	// __Host- or __Secure-. Empty by default.
	ServerSessionCookiePrefix string
	// ServerRequestBodyLimit is the max size in bytes for server-bound request
	// bodies in hooks and form submissions.
	// Default: 8 MB.
	ServerRequestBodyLimit int
	// ServerSessionCookieNoSecure disables the Secure attribute on the internal
	// Doors session cookie. Use only for plain HTTP development.
	ServerSessionCookieNoSecure bool
	// DisconnectHiddenTimer is how long hidden/background instances stay connected.
	// Default: InstanceTTL/2.
	DisconnectHiddenTimer time.Duration
	// RequestTimeout is the max duration of a client-server request.
	// Default: 30s.
	RequestTimeout time.Duration
	// SolitaireRollTime is the max lifetime of a solitaire sender or report
	// receiver request before rolling to a replacement request.
	// Default: 15s.
	SolitaireRollTime time.Duration
	// SolitaireSyncTimeout is the max pending duration of a server-to-client
	// sync task, including user calls. Exceeding this kills the instance.
	// Default: InstanceTTL.
	SolitaireSyncTimeout time.Duration
	// SolitaireFrameTime is the max time to buffer an outgoing server-to-client
	// frame before forcing a sync flush.
	// Default: ~33.3ms (30 FPS).
	SolitaireFrameTime time.Duration
	// SolitaireFrameSize is the max buffered bytes in an outgoing
	// server-to-client frame before forcing a sync flush.
	// Default: 32 KB.
	SolitaireFrameSize int
	// SolitaireDisableGzip disables gzip compression for solitaire sync payloads if true.
	SolitaireDisableGzip bool
	// SolitaireQueue is the max total queued plus unresolved
	// server-to-client sync tasks. Exceeding this kills the instance.
	// Default: 1024.
	SolitaireQueue int
	// SolitairePending is the max unresolved server-to-client sync tasks.
	// Throttles sending when reached. Default: 256.
	SolitairePending int
	// SolitaireDisableReportStreaming disables browser streaming request bodies for
	// client-to-server reports. When true, each report uses a standalone JSON
	// POST. Default: false.
	SolitaireDisableReportStreaming bool
	// SolitaireReportLimit is the max size of one client-to-server report
	// report. Default: 8 MB.
	SolitaireReportLimit int
	// SolitaireReportTimeout is the max time to receive and decode one
	// client-to-server report. Default: min(5s, SolitaireRollTime).
	SolitaireReportTimeout time.Duration
	// SolitaireMaxRTT caps the RTT estimate used for sync probing while the
	// server has pending work but no frame ready to flush. Values below
	// 2*SolitaireFrameTime are raised to that minimum. Default: 1s.
	SolitaireMaxRTT time.Duration
}

Conf defines global configuration for sessions, instances, client-server communication, and performance. Defaults are auto-initialized.

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 solitaire request roll interval.
	Roll time.Duration
	// FrameSize is the effective outgoing server-to-client frame size limit.
	FrameSize int
	// FlushTime is the effective outgoing server-to-client frame time limit.
	FlushTime time.Duration
	// DisableGzip is the effective solitaire payload gzip flag.
	DisableGzip bool
	// DisableReportStreaming is the effective report streaming flag.
	DisableReportStreaming bool
	// Queue is the effective queued plus unresolved sync task limit.
	Queue int
	// Pending is the effective unresolved sync task limit.
	Pending int
	// SyncTimeout is the effective sync task timeout.
	SyncTimeout time.Duration
	// ReportSize is the effective streaming report message size limit.
	ReportSize int
	// ReportTimeout is the effective single-report receive timeout.
	ReportTimeout time.Duration
	// MaxRTT is the effective RTT estimate cap after the 2*FlushTime minimum.
	MaxRTT time.Duration
}

func GetSolitaireConf

func GetSolitaireConf(s *Conf) *SolitaireConf

Jump to

Keyboard shortcuts

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