golang

package
v0.0.0-...-5ff71a8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2026 License: AGPL-3.0 Imports: 168 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

func GetExtensionMeta(pkg string) (*extension.Extension, error)

GetExtensionMeta returns the parsed metadata for a package.

func GetExtensions

func GetExtensions() []*extension.Extension

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

func Mirror(pkg string, url string) (any, error)

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

func ParseExtensionMetadata(pkg string) (*extension.Extension, error)

ParseExtensionMetadata parses metadata from a Scriggo extension source file. It delegates to the shared, runtime-agnostic parser in the extension package.

func Search(pkg string, page int, kw string, filter *proto.FilterSelection) ([]*proto.ExtensionListItem, error)

Search searches for content by keyword.

func Watch

func Watch(pkg string, url string) (any, *extension.Extension, error)

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) 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)

func (ExtensionRuntime) Watch

func (ExtensionRuntime) Watch(pkg string, url string) (any, *extension.Extension, 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 NewRuntime

func NewRuntime(vm VM) *Runtime

NewRuntime creates a new Scriggo runtime.

func (*Runtime) Call

func (r *Runtime) Call(name string, args ...Value) (Value, error)

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

func (r *Runtime) LoadExtension(ext *extension.Extension) error

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

func (v *ScriggoVM) Compile(pkg string, name string, source any) (*Program, error)

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.

func (*ScriggoVM) Run

func (v *ScriggoVM) Run(p *Program, opts *scriggo.RunOptions) (Value, error)

Run executes a compiled Scriggo program.

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.

type Value

type Value any

Value is a generic Scriggo value.

Directories

Path Synopsis
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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL