Documentation
¶
Overview ¶
Package bottle is the OS layer for running Go programs in a browser tab the way they run on Linux — the bottle a wasm ship sails in.
Two page-global primitives, one JS file each:
jsfs.js — an in-memory Linux-layout filesystem installed as
globalThis.fs / globalThis.process. Go's js/wasm runtime routes
the entire os package through this contract, so every wasm
instance on the page shares one POSIX-ish root: one program
writes /etc files, another reads them back.
fsbridge.js — the same filesystem, reachable from a Worker: a child blocks
in Atomics.wait while the page answers, which is the synchronous
syscall contract Go's runtime requires. See proc.spawnWorker.
vnet.js — a virtual loopback network: a page-global port table with
in-memory byte pipes, so an instance that LISTENS on
127.0.0.1:<port> can be DIALED from another instance — or from
page JS via vnet.httpFetch.
The vnet subpackage is the Go adapter: vnet.Listen / vnet.DialTimeout are net.Listen / net.DialTimeout on native builds, and route loopback addresses through the page table under js/wasm.
Load order matters: both scripts must run BEFORE a Go wasm instance starts (Go captures globalThis.fs at instance start). Application-specific filesystem layout is the page's job, via jsfs.mkdirp / jsfs.writeFile, in a script loaded after jsfs.js.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func COIRegisterJS ¶
func COIRegisterJS() []byte
COIRegisterJS returns coi-register.js — the page half of COISWJS. It registers the worker and reloads ONCE after it takes control, because the first navigation came from the server without the headers. Load it before anything that wants SharedArrayBuffer, and keep tolerating crossOriginIsolated being false on first paint.
func COISWJS ¶
func COISWJS() []byte
COISWJS returns coi-sw.js — the service worker that makes a page cross-origin isolated on a host that cannot set headers. It re-serves every response with COOP, COEP and CORP attached, which is what SharedArrayBuffer requires, and therefore what FSBridgeJS and proc.spawnWorker require.
Serve it at the page's own directory (the scope must cover the page) and load COIRegisterJS from the page. It does not conflict with vnet-sw.js: that registers at the narrower /vnet/ scope and keeps serving those URLs, which are same-origin, and COEP require-corp only demands CORP of CROSS-origin subresources.
func FSBridgeJS ¶
func FSBridgeJS() []byte
FSBridgeJS returns fsbridge.js — a blocking, synchronous view of the page's jsfs for code running in a Worker. proc.spawnWorker uses it to run a child off the main thread on the parent's filesystem, so a long build no longer freezes the tab. Serve it beside proc.js; the worker loads it by URL.
Requires cross-origin isolation (COOP/COEP) for SharedArrayBuffer. Without it spawnWorker refuses and callers fall back to proc.spawn.
func JSFS ¶
func JSFS() []byte
JSFS returns jsfs.js — the globalThis.fs / globalThis.process filesystem.
func ProcJS ¶
func ProcJS() []byte
ProcJS returns proc.js — the globalThis.proc process layer: spawn another wasm module from jsfs as a child that shares the page's fs and vnet, with per-process stdio, a process id, kill(), and an exit promise. A program too large to hold as bytes is bound to its path with proc.registerURL and streamed straight into the compiler. Load it after jsfs.js; wasm_exec.js may be loaded ahead of it or left to the first spawn. See the proc subpackage for the Go adapter.
func VNetJS ¶
func VNetJS() []byte
VNetJS returns vnet.js — the globalThis.vnet virtual loopback network.
func VNetSWJS ¶
func VNetSWJS() []byte
VNetSWJS returns vnet-sw.js — the service worker that turns virtual loopback ports into real same-origin URLs (/vnet/<port>/…), so iframes can load in-page servers with native resolution. Serve it at the page's directory as vnet-sw.js and call vnet.enableSW() from the page.
Types ¶
This section is empty.
Directories
¶
| Path | Synopsis |
|---|---|
|
example
|
|
|
proc/child
command
child: reads all of stdin, writes it back upper-cased, exits 3.
|
child: reads all of stdin, writes it back upper-cased, exits 3. |
|
proc/parent
command
parent: spawns /bin/child with a piped stdin, collects its stdout, and reports what came back and the exit code — all inside one browser tab, two wasm instances, one shared filesystem.
|
parent: spawns /bin/child with a piped stdin, collects its stdout, and reports what came back and the exit code — all inside one browser tab, two wasm instances, one shared filesystem. |
|
Package proc is the Go adapter for bottle's process layer (proc.js): spawn another wasm program from the page filesystem as a child that shares this tab's fs and vnet, wire its stdio, and wait for it to exit.
|
Package proc is the Go adapter for bottle's process layer (proc.js): spawn another wasm program from the page filesystem as a child that shares this tab's fs and vnet, wire its stdio, and wait for it to exit. |
|
Package vnet vnet/vnet_native.go
|
Package vnet vnet/vnet_native.go |