Documentation
¶
Overview ¶
Package httpfs is a read-only fs.FS over HTTP, for games that load their assets from a web server instead of embedding them: a browser build (js/wasm, where net/http uses fetch) or an editor webview reading the workspace. It uses the standard library only.
A file name is resolved against the base URL: with base "https://example.com/assets/", "hero/hero.png" is "https://example.com/assets/hero/hero.png". Directories cannot be listed; the asset system never lists them.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WatchChanges ¶
WatchChanges listens to the server-sent event stream at url (a development server that knows when asset files change) and returns a channel of changed asset keys: each event whose data is {"paths": ["hero/hero.png", ...]} becomes one batch, in order. Pass each batch to asset.Server.Changed on the game goroutine for hot reload in a browser build.
It reads the stream on its own goroutine with net/http (body streaming works on js/wasm) and never blocks the caller. When the connection drops or cannot be made it reconnects with a capped backoff, so a restarted dev server is picked up. An event that does not parse is logged and dropped. The goroutine runs for the life of the process and the channel is never closed; the buffer holds a few batches, after which the reader goroutine waits for the game to drain it.
Types ¶
type FS ¶
type FS struct {
// contains filtered or unexported fields
}
FS reads files with HTTP GET and stats them with HTTP HEAD. It implements fs.FS, fs.ReadFileFS and fs.StatFS. Calls block until the response is in, so on js/wasm keep them on the asset workers (the asset system's default), not on the game goroutine.
func New ¶
New returns an FS that reads files under baseURL. A nil client means http.DefaultClient. It returns an error if baseURL does not parse; a missing trailing slash is added, so the base always names a directory.