Help us shape the future of Go! Take the 2026 Go Developer Survey

scriptlib

package
v1.149.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package scriptlib is managed-script libraries (#1941): a library is a script with no main(), pure code another script loads by name and pinned version, load("lib:<name>@<version>", "fn").

A library is shared. Its code reaches nothing (no platform, no run), so loading it grants nothing, and a library's name is unique across the deployment, whoever owns it. A load names a version, and a saved version never changes, so a new version of a library changes no script that did not ask for it.

Every execution of a script resolves its loads through Loader over one Source: a run, a draft, a test and a behavior replay read the same pinned source, so a test and a run cannot disagree about the library's code.

Index

Constants

View Source
const MaxDepth = 8

MaxDepth is how many libraries deep a chain of loads may go. A chain longer than this is refused on save and at run time alike.

View Source
const Prefix = "lib:"

Prefix is the scheme a library load names.

View Source
const ResourcePrefix = "res:"

ResourcePrefix is the scheme a load of a managed resource's text names (#2113): load("res:<library>/<path>/<file>", PAGE_JS = "text") binds the file's text, as it was when the script was saved, to PAGE_JS. The rest of the module is the file's mcp:// address after the scheme.

Variables

View Source
var ErrNotFound = errors.New("no such library version")

ErrNotFound is what a Source answers for a library or version that does not exist.

Functions

func IsLibrary

func IsLibrary(file *syntax.File) bool

IsLibrary reports whether file is a library: it defines neither main() nor an endpoint's handle() at its top level (#2172).

func Loader

Loader is the thread's Load for an execution: each library version is read from src once, executed in env (the predeclared names a library sees), and its frozen globals handed to every load of it. A load while the same version is still loading is a cycle; a chain deeper than MaxDepth is refused.

func ResourceModules added in v1.145.0

func ResourceModules(source string) []string

ResourceModules is the res: modules source loads, in source order, each once. A source that does not parse names none.

func SourceIsLibrary

func SourceIsLibrary(source string) bool

SourceIsLibrary is IsLibrary over source; a source that does not parse is not a library.

Types

type Load

type Load struct {
	Ref      Ref
	Resource string
	Err      error
	Line     int
}

Load is one load statement: the library version it names, or the resource module it names (#2113), or the error its module string is, and its line.

func Loads

func Loads(file *syntax.File) []Load

Loads is every load statement of file, in source order.

type Problem

type Problem struct {
	Line    int
	Message string
}

Problem is one load a save is refused for.

func Check

func Check(ctx context.Context, src Source, source, self string) []Problem

Check resolves every load of source, and every load of the libraries it loads, against src: a save is refused for a load of a library or version that does not exist, a load cycle, or a chain deeper than MaxDepth. self is the library being saved, when it is one ("" otherwise), so a library that names itself is reported as the cycle it is. The findings are returned as one sentence each with its line in source.

type Ref

type Ref struct {
	Name    string `json:"name" example:"date-windows"`
	Version int    `json:"version" example:"2"`
}

Ref names one version of a library.

func ParseModule

func ParseModule(module string) (Ref, error)

ParseModule reads the module string of a load.

func Refs

func Refs(source string) []Ref

Refs is the library versions source loads, in source order, each once. A source that does not parse, and a load naming no library, contribute none.

func (Ref) String

func (r Ref) String() string

String is the module a load names the version by.

type ResourceSource added in v1.145.0

type ResourceSource interface {
	ResourceText(ctx context.Context, module string) (string, error)
}

ResourceSource reads the text a res: module names, as a Source that can answers it. A run reads the version its script version pinned; a draft and a test read the file as it is now.

type Source

type Source interface {
	LibrarySource(ctx context.Context, name string, version int) (string, error)
}

Source reads the source of one saved version of a library.

Jump to

Keyboard shortcuts

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