Documentation
¶
Overview ¶
Package static serves bundled / workspace files for the txco://static op, layered first-match-wins: a routed stack's own <workspace>/OPS/<stack>/FILES/** , the chassis-wide <workspace>/FILES/** , then the embedded chassis default (favicon.ico).
The set + the bytes are loaded into memory at startup and rebuilt on dbcache reload (see Index). A request NEVER touches the filesystem: Resolve is a pure in-memory radix lookup, so static serving and the boot pipeline that calls it stay off the disk critical path.
Index ¶
Constants ¶
const ( MaxIndexFiles = 2048 MaxIndexBytes = 64 << 20 MaxIndexDepth = 10 )
Index-build budget across the workspace layers (the embedded default is trusted and always loaded, exempt from these). Bounds the in-memory cache so a runaway FILES/ tree can't exhaust RAM; overflow is logged and skipped (already-indexed files still serve).
const MaxFileBytes = 1 << 20
MaxFileBytes caps any single static file. Same 1 MiB ceiling the continuation worker callback uses (server/personality/web/continuation.go). Larger files are skipped at index-build time (never read per request).
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index is the in-memory static set, three layers deep (per routed stack → chassis-wide → embedded). Trees are immutable (github.com/hashicorp/go-immutable-radix); Rebuild builds fresh ones and swaps under mu. Reads snapshot the pointers under mu then use the immutable structures lock-free — the processor.Unit.Mux idiom.
func NewIndex ¶
NewIndex builds the index immediately so the chassis serves correctly before the first reload.
func (*Index) Lookup ¶
Lookup resolves a request to a static file, layered first-match-wins, with try_files-style fallback so prerendered routes serve their own HTML for the extension-less URL a browser actually requests:
exact /assets/x.css → assets/x.css clean URL /about → about.html directory index /blog → blog/index.html root / → index.html
A path whose last segment already has an extension only probes the exact match (so /app.js never tries app.js.html or app.js/index.html). Backward-compatible: a path with no matching file still misses and, if it sits under a static-owned directory, reports Owned (→ 404) so the op answers 404 rather than leaking to app routing; a bare top-level miss passes through. Mirrors nginx try_files / Caddy / the layout adapter-static emits. Pure in-memory; no filesystem access.
func (*Index) Rebuild ¶
func (ix *Index) Rebuild()
Rebuild reloads every layer from disk + embed into fresh structures and atomically swaps them in. Called at startup and on dbcache reload — never on the request path.
func (*Index) RebuildTenant ¶ added in v0.2.6
RebuildTenant reloads the tenant FILES/ metadata layer (path → content hash + size, no bytes) from the runtime DB and atomically swaps it in. Modeled on admission.Rebuild: nil-safe, and it keeps the prior layer on any error so a transient DB hiccup never blanks tenant serving. db is the handle passed by dbcache.OnReload (or dbc.Snapshot() for the initial build) — never capture dbc.Db.
type Result ¶
type Result struct {
Found bool
Owned bool
Body []byte // set for inline (operator) layers
// Hash is set for a tenant CAS entry instead of Body: the caller
// resolves the bytes from the filecas store by this content hash.
Hash string
Size int64
Ctype string
ETag string
}
Result is the outcome of a Lookup.
Found → an exact file; serve Body (200) or 304 on ETag match.
!Found && Owned → request is under a static-owned directory prefix;
the op must answer 404 (NOT fall through).
!Found && !Owned → not static's; the op returns "{}" (keep routing).