fetcher-go

command
v0.24.1 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 7 Imported by: 0

README

Fetcher Plugin (Go)

fetcher-go is the full-example plugin. One binary serves everything a plugin can:

  • a fetcher — the one RegisterFetcher("demo", ...) call — owning the demo:// scheme: a virtual library at demo://libs (modules under lib/, any depth of nesting) plus single-file script sources (demo://scripts/...)
  • a function and a class under plugin.demo, like any Go plugin

The host synthesizes the package layout itself and asks for each file only when an import or read actually touches it, so files nothing reads (most of docs/ and data/) are never transferred.

go build -o /tmp/scriptling-plugins/fetcher-go ./examples/plugins/fetcher-go

# the plugin's library attaches automatically, so no --package is needed
scriptling --plugin /tmp/scriptling-plugins/fetcher-go -c 'import greet; print(greet.greeting("Ada"))'

# run a script served by the plugin (scripts are refetched on every run)
scriptling --plugin /tmp/scriptling-plugins/fetcher-go demo://scripts/hello Ada

# the tour: namespaced modules, static assets, the function and the class
scriptling --plugin /tmp/scriptling-plugins/fetcher-go demo://scripts/tour

It serves:

  • demo://libs — the library: lib/greet.py, lib/calc.py, packages lib/hub/, lib/fred/ (one level, import fred) and lib/blah/blah/ (two levels, import blah.blah), plus static assets docs/ and data/
  • demo://scripts/hello, demo://scripts/tour — single-file script sources
  • demo://scripts/setup — a JSON-RPC setup script for server modes

Static assets are read from scripts through scriptling.package, using the plugin's name (demo) as the package name:

import scriptling.package as package

text = package.read_file("demo", "docs/getting-started.md")
docs = package.glob("demo", "**/*.md")

The Read handler just returns the bytes. The host caches nothing it fetches, so every read reaches the plugin and nothing is written to the package cache:

scriptling --cache-dir /tmp/demo-cache --plugin /tmp/scriptling-plugins/fetcher-go \
           -c 'import greet'
ls /tmp/demo-cache   # empty: plugin content is never persisted

A fetcher whose backend is slow enough to want caching does it inside Read; there is no host-side cache and no conditional-read protocol to hook into.

Setup scripts work in the server modes, with handler modules arriving from the plugin's library:

printf '{"jsonrpc":"2.0","id":1,"method":"demo.add","params":{"a":2,"b":3}}\n' |
  scriptling --plugin /tmp/scriptling-plugins/fetcher-go --json-rpc demo://scripts/setup

See the website's plugin fetchers documentation for the Fetcher interface (Read and Glob) and the wire protocol (fetch.read / fetch.glob), and the fetcher plugin tutorial for a walkthrough of this example.

Documentation

Overview

fetcher-go is the full-example plugin: it registers a function and a class like any Go plugin (importable as plugin.demo), and additionally serves a fetcher — the one RegisterFetcher("demo", ...) call — so the same plugin owns the demo:// scheme. It serves a virtual library (demo://libs, modules under lib/, any depth of nesting), static assets (markdown, json) and single-file script sources (demo://scripts/hello), all from memory, on demand. Run it with:

scriptling --plugin /tmp/scriptling-plugins/fetcher-go \
           -c 'import greet; print(greet.greeting("World"))'
scriptling --plugin /tmp/scriptling-plugins/fetcher-go demo://scripts/tour

The host only asks for the files an import or read actually touches, and caches nothing it fetches, so the example returns content plainly.

Jump to

Keyboard shortcuts

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