Documentation
¶
Overview ¶
Package golang implements the Go (Scriggo) extension runtime.
This file holds the public endpoint surface only -- the six entry points the host calls on an extension, plus metadata access. The supporting machinery lives alongside it:
invoke.go compiling an extension and calling an entry point filter_bridge.go proto <-> runtime filter conversion convert_reflect.go generic reflection field readers convert_list.go list/detail/mirror-group converters convert_watch.go watch-shape routing and per-type watch converters media_policy.go content-type classification, TLS profile, proxy URLs
Index ¶
- Variables
- func CreateFilter(pkg string, filter *proto.FilterSelection) (map[string]*proto.ExtensionFilter, error)
- func Detail(pkg string, url string) (*proto.ExtensionDetail, error)
- func GetExtensionMeta(pkg string) (*extension.Extension, error)
- func GetExtensions() []*extension.Extension
- func HandleReload(pkg string)
- func Latest(pkg string, page int) ([]*proto.ExtensionListItem, error)
- func LoadExtensions()
- func Mirror(pkg string, url string) (any, error)
- func ParseExtensionMetadata(pkg string) (*extension.Extension, error)
- func Search(pkg string, page int, kw string, filter *proto.FilterSelection) ([]*proto.ExtensionListItem, error)
- func Watch(pkg string, url string) (any, *extension.Extension, error)
- type ExtensionRuntime
- func (ExtensionRuntime) CreateFilter(pkg string, filter *proto.FilterSelection) (map[string]*proto.ExtensionFilter, error)
- func (ExtensionRuntime) Detail(pkg string, url string) (*proto.ExtensionDetail, error)
- func (ExtensionRuntime) GetExtensionMeta(pkg string) (*extension.Extension, error)
- func (ExtensionRuntime) Latest(pkg string, page int) ([]*proto.ExtensionListItem, error)
- func (ExtensionRuntime) Mirror(pkg string, url string) (any, error)
- func (ExtensionRuntime) Search(pkg string, page int, kw string, filter *proto.FilterSelection) ([]*proto.ExtensionListItem, error)
- func (ExtensionRuntime) Watch(pkg string, url string) (any, *extension.Extension, error)
- type Program
- type Runtime
- type ScriggoVM
- type Scriggofile
- type VM
- type Value
Constants ¶
This section is empty.
Variables ¶
var ExtensionDir string
ExtensionDir is the directory where Scriggo extensions are stored.
Functions ¶
func CreateFilter ¶
func CreateFilter(pkg string, filter *proto.FilterSelection) (map[string]*proto.ExtensionFilter, error)
CreateFilter creates filter options for a package. It invokes the extension's CreateFilter entry point (mirroring the JavaScript V2 createFilter() contract) and converts the returned map[string]runtime.FilterDefinition into the proto representation. Extensions that do not declare CreateFilter produce nil with no error.
func Detail ¶
func Detail(pkg string, url string) (*proto.ExtensionDetail, error)
Detail returns detailed information about a content item.
func GetExtensionMeta ¶
GetExtensionMeta returns the parsed metadata for a package.
func GetExtensions ¶
GetExtensions returns the parsed metadata of every Go/Scriggo extension available in ExtensionDir. Unlike LoadExtensions (which only eagerly runs extensions that declare a Load entry point), this lists all discoverable .go extensions so the frontend can present them alongside the JavaScript extensions. The returned metadata has Context (source) stripped to keep the payload small. A file that fails to parse is returned with its Error field set rather than being omitted.
func HandleReload ¶
func HandleReload(pkg string)
HandleReload is the Go-specific reload handler invoked by the unified extension watcher when a .go file changes. It invalidates the per-package cross-call variable cache and the per-package native packages map so the next request recompiles against the updated source.
func Latest ¶
func Latest(pkg string, page int) ([]*proto.ExtensionListItem, error)
Latest returns the latest content for a package.
func LoadExtensions ¶
func LoadExtensions()
LoadExtensions scans ExtensionDir and eagerly loads every Go/Scriggo extension through its Load entry point. This mirrors the JavaScript runtime's startup scan (jsext.InitRuntime) so that Go extensions are visibly loaded at boot -- each prints "Extension loaded (Vx) [GO]: ..." -- and any compile error is surfaced early.
Extensions that have no Load entry point (they are driven solely by the endpoint functions, e.g. Search/Latest, such as the sample example extension) cannot use this eager path and continue to be compiled lazily on first request; they are skipped here without error.
func Mirror ¶
Mirror resolves the chosen source (the mirror URL the user picked from the Watch list) into the final watchable resource. Under the V2 layout Watch() only yields the list of mirrors; the actual stream link -- and any torrent that needs resolving -- is produced here, mirroring the JavaScript V2 step. The returned value is a proto per-type watch (bangumi/manga/fikushon/all) whose concrete shape follows the extension's declared @type.
func ParseExtensionMetadata ¶
ParseExtensionMetadata parses metadata from a Scriggo extension source file. It delegates to the shared, runtime-agnostic parser in the extension package.
func Search ¶
func Search(pkg string, page int, kw string, filter *proto.FilterSelection) ([]*proto.ExtensionListItem, error)
Search searches for content by keyword.
func Watch ¶
Watch returns watch/stream information for a content item. The returned *extension.Extension carries the ApiVersion/WatchType used by callers to pick a response shape.
The Golang (Scriggo) V2 backend emits exactly two watch shapes from Watch(): the generic V2 ExtensionWatch (the source/group list, resolved via Mirror), or the combined ExtensionAllMirror (carrying the manga/fikushon/bangumi members behind @type all). A standalone per-type watch (manga/fikushon/bangumi) is not a valid Watch() return for golang extensions; those shapes only appear as members of ExtensionAllMirror. toWatchValue routes the result to the right proto message based on the concrete script struct.
Types ¶
type ExtensionRuntime ¶
type ExtensionRuntime struct{}
ExtensionRuntime adapts the Golang (Scriggo) extension package to the shared endpoint.Runtime interface. It satisfies the interface structurally (no import of the endpoint package is required).
The Golang backend is v2-only: extensions are always compiled against the v2 API, so there is no v1 legacy path to handle here. It is named ExtensionRuntime to avoid colliding with the VM Runtime type in vm.go.
func (ExtensionRuntime) CreateFilter ¶
func (ExtensionRuntime) CreateFilter(pkg string, filter *proto.FilterSelection) (map[string]*proto.ExtensionFilter, error)
func (ExtensionRuntime) Detail ¶
func (ExtensionRuntime) Detail(pkg string, url string) (*proto.ExtensionDetail, error)
func (ExtensionRuntime) GetExtensionMeta ¶
func (ExtensionRuntime) GetExtensionMeta(pkg string) (*extension.Extension, error)
func (ExtensionRuntime) Latest ¶
func (ExtensionRuntime) Latest(pkg string, page int) ([]*proto.ExtensionListItem, error)
func (ExtensionRuntime) Mirror ¶
func (ExtensionRuntime) Mirror(pkg string, url string) (any, error)
func (ExtensionRuntime) Search ¶
func (ExtensionRuntime) Search(pkg string, page int, kw string, filter *proto.FilterSelection) ([]*proto.ExtensionListItem, error)
type Program ¶
type Program struct {
// contains filtered or unexported fields
}
Program represents compiled Scriggo code.
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
Runtime is the Scriggo runtime environment.
func (*Runtime) Call ¶
Call invokes a function exported by the loaded extension on the Scriggo runtime. It relies on the local Scriggo build's Program.Call method, which looks up the function by name and evaluates it with the given arguments.
Call must be preceded by LoadExtension; otherwise it returns an error.
func (*Runtime) LoadExtension ¶
LoadExtension loads a Scriggo extension into the runtime.
The extension is built with "Load" as its entry point: the Load function declared in the extension source is run once (via Run) to set up and extend the runtime. The compiled program is kept in the runtime so that the specific functions exported by the extension can later be invoked with Call, using the local Scriggo build that supports calling a function by name.
type ScriggoVM ¶
type ScriggoVM struct {
// contains filtered or unexported fields
}
ScriggoVM implements the VM interface using Scriggo.
func NewScriggoVM ¶
func NewScriggoVM(scriggoFile *Scriggofile) *ScriggoVM
NewScriggoVM creates a new Scriggo VM.
func (*ScriggoVM) Compile ¶
Compile compiles extension source code using Scriggo.
It builds directly from the source in memory. scriggo.Files is an fs.FS backed by a map, and scriggo.Build compiles entirely in memory, so there is no need to materialize a temporary directory or file on disk.
When pkg is non-empty the per-package native packages map is used so host primitives (fmt.Print / Fetch) emit dev-dashboard events tagged with the correct package. When pkg is empty the global packages map is used as-is.
type Scriggofile ¶
type Scriggofile struct {
// Packages lists allowed native packages.
Packages []string `json:"packages"`
}
Scriggofile represents the Scriggo configuration file.
type VM ¶
type VM interface {
// Compile compiles extension source code for the given extension package.
// When pkg is non-empty, the per-package native packages map is used so
// host primitives (fmt.Print / Fetch) are tagged with the correct package
// for the dev dashboard. When pkg is empty the global packages map is left
// untouched.
Compile(pkg string, name string, source any) (*Program, error)
// Run executes a compiled program.
Run(*Program, *scriggo.RunOptions) (Value, error)
}
VM is the Scriggo/Go-subset extension runtime.