Documentation
¶
Index ¶
- Constants
- Variables
- func ClearCache(cacheDir string) error
- func DefaultCacheDir() (string, error)
- func Fetch(source string, insecure bool) ([]byte, error)
- func FetchFile(path string, maxSize ...int64) ([]byte, error)
- func FetchWithCache(source string, insecure bool, cacheDir string, maxSize ...int64) ([]byte, error)
- func HashBytes(data []byte) string
- func IsURL(source string) bool
- func Pack(srcDir, dst string, force bool) (string, error)
- func PruneCache(cacheDir string, ttl time.Duration) error
- func Unpack(src string, opts UnpackOptions) error
- func UnpackRemove(src string, insecure bool, destDir string) error
- type DirDocReader
- type DocReader
- type Loader
- func (l *Loader) AddFromPath(source string, insecure bool) error
- func (l *Loader) AddPackage(p *Package)
- func (l *Loader) Description() string
- func (l *Loader) GetMainEntry() (module, function string, found bool)
- func (l *Loader) Load(name string) (string, bool, error)
- func (l *Loader) SetCacheDir(dir string)
- func (l *Loader) SetFallback(fallback libloader.LibraryLoader)
- type Manifest
- type Package
- type UnpackOptions
- type ZipDocReader
Constants ¶
const ( DefaultMaxPackageSize int64 = 100 * 1024 * 1024 // 100MB DefaultCacheTTL = 7 * 24 * time.Hour // 7 days )
const ( Extension = ".zip" ManifestFile = "manifest.toml" LibDir = "lib" DocsDir = "docs" )
Variables ¶
var ( ErrInvalidPackage = errors.New("invalid package format") ErrMissingManifest = errors.New("missing manifest.toml") ErrInvalidManifest = errors.New("invalid manifest format") ErrModuleNotFound = errors.New("module not found in package") ErrFetchFailed = errors.New("failed to fetch package") )
Functions ¶
func ClearCache ¶
ClearCache removes all cached packages from cacheDir. If cacheDir is empty, uses the OS default cache directory.
func DefaultCacheDir ¶
DefaultCacheDir returns the default cache directory for packages.
func Fetch ¶
Fetch loads bytes from a URL or local path. For URLs, uses the cache with ETag/Last-Modified freshness checks.
func FetchWithCache ¶
func FetchWithCache(source string, insecure bool, cacheDir string, maxSize ...int64) ([]byte, error)
FetchWithCache loads bytes from a URL or local path, using cacheDir for remote URLs. If cacheDir is empty, uses the OS default cache directory. An optional #sha256=<hex> fragment on source is stripped before fetching and used to verify the downloaded bytes; a mismatch is a fatal error. maxSize limits download size (0 = use DefaultMaxPackageSize).
func Pack ¶
Pack creates a package from srcDir, writing to dst. Reads manifest.toml from srcDir. Use force to overwrite an existing dst. Returns the SHA-256 hex hash of the written package.
func PruneCache ¶
PruneCache removes cache entries that have not been accessed within ttl. If cacheDir is empty, uses the OS default cache directory. If ttl is 0, uses DefaultCacheTTL. Each cache entry is a .zip/.meta pair; the .zip mod time tracks last access.
func Unpack ¶
func Unpack(src string, opts UnpackOptions) error
Unpack extracts a package from a local path or URL.
Types ¶
type DirDocReader ¶
type DirDocReader struct {
// contains filtered or unexported fields
}
DirDocReader reads docs from an unpacked package directory.
func NewDirDocReader ¶
func NewDirDocReader(dir string) *DirDocReader
NewDirDocReader creates a DocReader for an unpacked package directory.
func (*DirDocReader) ListDocs ¶
func (r *DirDocReader) ListDocs() []string
func (*DirDocReader) Name ¶
func (r *DirDocReader) Name() string
type DocReader ¶
type DocReader interface {
// Name returns a display name for this source.
Name() string
// ListDocs returns all doc file paths relative to docs/ (e.g. "guide.md").
ListDocs() []string
// ReadDoc reads a doc file by its relative path.
ReadDoc(name string) ([]byte, error)
}
DocReader provides access to docs/ content from a package source.
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader implements libloader.LibraryLoader over a set of packages. Packages are searched in reverse order (last added = highest priority).
func (*Loader) AddFromPath ¶
AddFromPath loads a .zip package from a local path or URL. source may include a #sha256=<hex> fragment for integrity verification.
func (*Loader) AddPackage ¶
AddPackage adds a package to the loader.
func (*Loader) Description ¶
Description implements libloader.LibraryLoader.
func (*Loader) GetMainEntry ¶
GetMainEntry returns the main entry point from the last package that defines one. Returns module, function, and whether one was found.
func (*Loader) Load ¶
Load implements libloader.LibraryLoader. Searches packages in reverse order (last = highest priority), then fallback.
func (*Loader) SetCacheDir ¶
SetCacheDir overrides the default OS cache directory for remote packages.
func (*Loader) SetFallback ¶
func (l *Loader) SetFallback(fallback libloader.LibraryLoader)
SetFallback sets the fallback loader used when no package provides the module.
type Manifest ¶
type Manifest struct {
Name string `toml:"name"`
Version string `toml:"version"`
Description string `toml:"description,omitempty"`
Main string `toml:"main,omitempty"` // module.function entry point
}
Manifest describes package metadata.
func ReadManifestFromDir ¶
ReadManifestFromDir reads manifest.toml from a source directory.
type Package ¶
type Package struct {
Manifest Manifest
// contains filtered or unexported fields
}
Package represents a loaded package. All file contents are decompressed into memory at Open time. docs/ entries are intentionally excluded; use ZipDocReader for those.
func (*Package) HasDocs ¶
HasDocs returns true if the package contains a docs folder. Since docs/ is not loaded into p.files, we track this separately.
type UnpackOptions ¶
UnpackOptions configures extraction behaviour.
type ZipDocReader ¶
type ZipDocReader struct {
// contains filtered or unexported fields
}
ZipDocReader reads docs from a zip package file.
func NewZipDocReader ¶
func NewZipDocReader(src string, insecure bool) (*ZipDocReader, error)
NewZipDocReader opens a zip and extracts only the docs/ entries.
func (*ZipDocReader) ListDocs ¶
func (r *ZipDocReader) ListDocs() []string
func (*ZipDocReader) Name ¶
func (r *ZipDocReader) Name() string