Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Unmarshal ¶
Unmarshal decodes an arbitrary value (typically produced by a script runtime such as goja) into a value of type T, honouring the `json` tag and converting byte slices into base64-encoded strings.
It is intentionally runtime-agnostic so that both the JS and Golang extension runtimes can share it without creating an import cycle.
func UnmarshalList ¶
UnmarshalList decodes a list of arbitrary values into a slice of *T.
func WatchExtensions ¶
func WatchExtensions(dirs []string, onChange func(lang Language, pkg string)) (*fsnotify.Watcher, error)
WatchExtensions watches the given directories and invokes onChange whenever a supported extension source file is created, written, removed or renamed. The language passed to onChange is decided by the changed file's extension, so callers can route the event to the correct runtime. The returned watcher can be closed by the caller to stop watching.
Types ¶
type Extension ¶
type Extension struct {
Name string `json:"name"`
Version string `json:"version"`
Author string `json:"author"`
License string `json:"license"`
Lang string `json:"lang"`
Icon string `json:"icon"`
Pkg string `json:"package"`
Website string `json:"webSite"`
Description string `json:"description"`
Tags []string `json:"tags"`
ApiVersion string `json:"apiVersion"`
Error string `json:"error,omitempty"`
Context *string
WatchType WatchType `json:"type"`
// FileLang is the runtime language detected from the source file's
// extension (".js" -> LanguageJS, ".go" -> LanguageGolang). It is set by
// ParseExtensionMetadata and lets each runtime route an extension to the
// correct backend without re-deriving the language from the (metadata)
// Name field. The metadata @lang value is unrelated and lives in Lang.
FileLang Language `json:"-"`
}
func FilterExtensions ¶
FilterExtensions scans a directory and returns the parsed metadata of every supported extension source file, plus a map of invalid file -> error message (so runtimes can surface load failures). It is universal: each file's language is detected by extension and its metadata parsed accordingly.
func ParseExtensionMetadata ¶
ParseExtensionMetadata parses the // ==MiruExtension== metadata header shared by both runtimes (the same @key value format) into a shared Extension value. It is universal: it does not depend on any particular runtime, only on the file's name/extension.
The parsed source is stored in Extension.Context so runtimes that need the raw source (e.g. the JS runtime compiling into goja) can access it.
Two per-runtime quirks are preserved so callers get exactly the previous result:
- The JS runtime requires <package>.<ext> to equal the file name; the Golang runtime historically does not validate the file name, so validation is skipped for .go files.
- The JS runtime defaults a missing/non-"2" apiVersion to "1"; the Golang runtime keeps the raw value (it is v2-only and the caller supplies it).
type Language ¶
type Language string
Language identifies the runtime that backs an extension source file. The language is decided purely by the source file's extension; this is the single, centralized routing decision used across the whole codebase.
const ( // LanguageJS is the JavaScript (goja) runtime, backed by .js files. LanguageJS Language = ".js" // LanguageGolang is the Golang (Scriggo) runtime, backed by .go files. LanguageGolang Language = ".go" // LanguageUnknown is returned when a file's extension is not a known runtime. LanguageUnknown Language = "" )
func DetectLanguage ¶
DetectLanguage returns the runtime Language for a source file, based solely on its extension. This is the centralized router: a file's suffix decides whether it is handled by the JavaScript or Golang runtime.
type WatchType ¶
type WatchType string
WatchType is the constrained set of content kinds an extension can watch. It is a string-backed enum limited to exactly four values; the parser rejects any @type that is not one of these.
const ( // WatchTypeBangumi is video streaming (anime) content. WatchTypeBangumi WatchType = "bangumi" // WatchTypeManga is comic / image-page content. WatchTypeManga WatchType = "manga" // WatchTypeFikushon is novel / text content. WatchTypeFikushon WatchType = "fikushon" // WatchTypeAll is the combined type carrying manga + fikushon + bangumi. WatchTypeAll WatchType = "all" )
func ParseWatchType ¶
ParseWatchType validates a raw @type string against the allowed WatchType values. It returns an error for anything other than the four known kinds so that non-conforming extensions fail fast at load time.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package golang implements the Go (Scriggo) extension runtime.
|
Package golang implements the Go (Scriggo) extension runtime. |
|
sdk
Package sdk is the public, importable API surface that Miru Go (Scriggo) extension authors use.
|
Package sdk is the public, importable API surface that Miru Go (Scriggo) extension authors use. |