common

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: AGPL-3.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

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) map[string]string

func Catch

func Catch(f func()) (err error)

func CatchValue

func CatchValue[V any](f func() V) (value V, err error)

func EncodeId

func EncodeId(b []byte) string

func Hash

func Hash(input []byte) string

func InitDefaults

func InitDefaults(s *SystemConf)

InitDefaults fills zero or invalid values in s with Doors defaults.

func MinifyCSS

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

func NewJsonWriter

func NewJsonWriter(w io.Writer) io.Writer

func RandId

func RandId() string

func Ts

func Ts()

func Zip

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

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>
	FrameAcestors []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 struct {
	// contains filtered or unexported fields
}

CSPCollector accumulates hashes and dynamic sources that should be added to a CSP during one response.

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

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

func NewPrime

func NewPrime() *Prime

func (*Prime) Gen

func (p *Prime) Gen() uint64

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 {
	Ping         time.Duration
	FlushSize    int
	RollDuration time.Duration
	FlushTimeout time.Duration
	DisableGzip  bool
	Queue        int
	Pending      int
	SyncTimeout  time.Duration
}

func GetSolitaireConf

func GetSolitaireConf(s *SystemConf) *SolitaireConf

type SystemConf

type SystemConf 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: 16.
	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
	// 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
	// SolitairePing is the max time before rolling the request.
	// Default: 15s.
	SolitairePing time.Duration
	// SolitaireSyncTimeout is the max pending duration of a server→client sync task,
	// including user calls. Exceeding this kills the instance.
	// Default: InstanceTTL.
	SolitaireSyncTimeout time.Duration
	// SolitaireRollTimeout is how long an active sync connection lasts before
	// rolling to a new one if the queue is long. Default: 1s.
	SolitaireRollTimeout time.Duration
	// SolitaireFlushTimeout is the max time before forcing a flush.
	// Default: 30ms
	SolitaireFlushTimeout time.Duration
	// SolitaireFlushSizeLimit is the max buffered bytes before forcing a flush.
	// Default: 32 KB
	SolitaireFlushSizeLimit int
	// SolitaireDisableGzip disables gzip compression for solitaire sync payloads if true.
	SolitaireDisableGzip bool
	// SolitaireQueue is the max queued server→client sync task.
	// Exceeding this kills the instance. Default: 1024.
	SolitaireQueue int
	// SolitairePending is the max unresolved server→client sync tasks.
	// Throttles sending when reached. Default: 256.
	SolitairePending int
}

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

Jump to

Keyboard shortcuts

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