common

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2025 License: UNKNOWN not legal advice Imports: 0 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CtxKeyInstance ctxKey = iota
	CtxKeyDoor
	CtxKeyThread
	CtxKeyRenderMap
	CtxKeyBlocking
	CtxKeyAdapters
	CtxKeySessionStore
	CtxKeyInstanceStore
	CtxKeyParent
	CtxKeyAttrs
	CtxStorageKeyStatus
)
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 Catch

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

func CatchValue

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

func ClearBlockingCtx

func ClearBlockingCtx(ctx context.Context) context.Context

func Debug

func Debug(a any) string

func GetChildren

func GetChildren(ctx context.Context) (context.Context, templ.Component, bool)

func Hash

func Hash(input []byte) string

func InitDefaults

func InitDefaults(s *SystemConf)

func IsBlockingCtx

func IsBlockingCtx(ctx context.Context) bool

func IsNill

func IsNill(i any) bool

func LogBlockingWarning

func LogBlockingWarning(ctx context.Context, entity string, operation string)

func LogCanceled

func LogCanceled(ctx context.Context, action string)

func MarshalJSON

func MarshalJSON(value any) ([]byte, error)

func MinifyCSS

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

func RandId

func RandId() string

func RenderError

func RenderError(msg string) templ.Component

func RenderErrorLog

func RenderErrorLog(ctx context.Context, w io.Writer, message string, args ...any) error

func SetBlockingCtx

func SetBlockingCtx(ctx context.Context) context.Context

func StripN

func StripN(buf []byte) []byte

func Ts

func Ts()

func Zip

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

Types

type Attrs

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

func NewAttrs

func NewAttrs() *Attrs

func (*Attrs) AppendArray

func (a *Attrs) AppendArray(name string, value any)

func (*Attrs) Items

func (a *Attrs) Items() []templ.KeyValue[string, any]

func (*Attrs) Join

func (a *Attrs) Join(attrs *Attrs)

func (*Attrs) Set

func (a *Attrs) Set(name string, value any)

func (*Attrs) SetObject

func (a *Attrs) SetObject(name string, value any)

func (*Attrs) SetRaw

func (a *Attrs) SetRaw(attrs templ.Attributes)

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
}

func (*CSP) NewCollector

func (c *CSP) NewCollector() *CSPCollector

type CSPCollector

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

func (*CSPCollector) Generate

func (c *CSPCollector) Generate() string

func (*CSPCollector) ScriptHash

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

func (*CSPCollector) ScriptSource

func (c *CSPCollector) ScriptSource(source string)

func (*CSPCollector) StyleHash

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

func (*CSPCollector) StyleSource

func (c *CSPCollector) StyleSource(source string)

type Expirator

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

func NewExpirator

func NewExpirator(on func()) *Expirator

func (*Expirator) Report

func (x *Expirator) Report(id uint64)

func (*Expirator) Shutdown

func (x *Expirator) Shutdown()

func (*Expirator) Track

func (x *Expirator) Track(id uint64, expire time.Time)

type FuncCollector

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

func NewFuncCollector

func NewFuncCollector() *FuncCollector

func (*FuncCollector) Add

func (c *FuncCollector) Add(f func())

func (*FuncCollector) Apply

func (c *FuncCollector) Apply()

type Primea

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

func NewPrima

func NewPrima() *Primea

func (*Primea) Gen

func (p *Primea) Gen() uint64

type RenderMap

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

func NewRenderMap

func NewRenderMap() *RenderMap

func (*RenderMap) AddImport

func (r *RenderMap) AddImport(specifier string, path string)

func (*RenderMap) Destroy

func (r *RenderMap) Destroy()

func (*RenderMap) InitImportMap

func (r *RenderMap) InitImportMap(c *CSPCollector)

func (*RenderMap) Render

func (r *RenderMap) Render(w io.Writer, index uint64) error

func (*RenderMap) RenderBuf

func (r *RenderMap) RenderBuf(w io.Writer, buf []byte) error

func (*RenderMap) WriteAttrs

func (r *RenderMap) WriteAttrs(w io.Writer, attr *Attrs) error

func (*RenderMap) WriteImportMap

func (r *RenderMap) WriteImportMap(w io.Writer) error

func (*RenderMap) Writer

func (r *RenderMap) Writer(index uint64) (*RenderWriter, bool)

type RenderWriter

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

func (*RenderWriter) Holdplace

func (rw *RenderWriter) Holdplace(w io.Writer) error

func (*RenderWriter) Len

func (rw *RenderWriter) Len() int

func (*RenderWriter) Submit

func (rw *RenderWriter) Submit()

func (*RenderWriter) SubmitEmpty

func (rw *RenderWriter) SubmitEmpty()

func (*RenderWriter) SubmitError

func (rw *RenderWriter) SubmitError(err error, args ...any)

func (*RenderWriter) Write

func (w *RenderWriter) Write(b []byte) (int, error)

type Set

type Set[T comparable] struct {
	// contains filtered or unexported fields
}

func NewSet

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

func (*Set[T]) Add

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

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
	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.
	// Default behavior (value 0): session ends, when no more
	// instances left, cookie expires when browser closes.
	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 (hook).
	// Default: 30s.
	RequestTimeout time.Duration
	// SolitairePing is the max idle 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
	// 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.

type Writable

type Writable interface {
	Destroy()
	Write(io.Writer) error
}

type WritableNone

type WritableNone struct{}

func (WritableNone) Destroy

func (w WritableNone) Destroy()

func (WritableNone) Write

func (w WritableNone) Write(io.Writer) error

type WritableRenderMap

type WritableRenderMap struct {
	Rm    *RenderMap
	Index uint64
}

func (*WritableRenderMap) Destroy

func (wrm *WritableRenderMap) Destroy()

func (*WritableRenderMap) Write

func (wrm *WritableRenderMap) Write(w io.Writer) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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