Documentation
¶
Overview ¶
Package modfs implements an io/fs.FS backed by the Go module proxy protocol. It fetches modules over HTTP on demand and caches them in memory, so no module sources are written to disk. This makes it usable from WASM and other restricted environments.
The filesystem is plugged into goparser.Parser as a third-tier fallback after the user pkgfs and the embedded stdlib source FS, so any import path the parser cannot resolve locally is fetched dynamically.
Index ¶
Constants ¶
const DefaultProxy = "https://proxy.golang.org"
DefaultProxy is the public Go module proxy.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FS ¶
type FS struct {
// contains filtered or unexported fields
}
FS is an in-memory filesystem that resolves Go import paths against a module proxy. It implements fs.FS, fs.StatFS and fs.ReadDirFS.
func (*FS) Inject ¶
Inject installs a pre-fetched module into the in-memory cache. The zipBytes must use the standard Go module proxy layout (entries rooted at "<modPath>@<version>/"). After Inject, lookups under modPath are served from memory without network access. Any prior negative cache entry for modPath itself is cleared so locate() can find it.
func (*FS) Open ¶
Open implements fs.FS. The name is an import path or a path inside one (e.g. "github.com/foo/bar" or "github.com/foo/bar/sub/file.go").
type NetStats ¶ added in v0.3.0
NetStats summarizes the network work performed by an FS instance: proxy requests issued (200s and failures), bytes consumed from response bodies, and total wall-clock time spent in proxyGet.
Cache hits, Inject calls, and offline lookups do not contribute -- only real HTTP requests do. Snapshot the counters with FS.NetStats.
type Options ¶
type Options struct {
// Proxy is the module proxy base URL. Empty means DefaultProxy.
Proxy string
// Client is the HTTP client used for proxy requests. Empty means
// http.DefaultClient.
Client *http.Client
// Offline disables proxy fetches. Only modules added via Inject are
// served; any other lookup returns fs.ErrNotExist. Useful for
// playground/WASM and GOPROXY=off, where the embedded stdlib zip is the
// sole source.
Offline bool
}
Options configures FS construction.