interp

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package interp is the generic mechanism for loading Go "policy" source at runtime: read a directory of .go files, compile them as a named package under a fresh yaegi interpreter, inject a set of host symbols the policy may import, and evaluate an expression (typically a function symbol) that the caller type-asserts and calls. A fresh interpreter per Load means a reload drops the previous code cleanly.

It bakes in no entrypoint contract: the package name, the injected symbols, and the evaluated expression are all parameters, so any program can load its own interpreted policy against its own host interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(dir, pkgName string, inject Inject, evalExpr string) (reflect.Value, error)

Load reads the flat *.go files in dir, maps them as package pkgName under a fresh yaegi interpreter, makes stdlib plus inject available, imports the package, and evaluates evalExpr — returning the resulting value for the caller to type-assert. evalExpr is typically "pkgName.Symbol".

Types

type Inject

type Inject map[string]map[string]reflect.Value

Inject maps an import path (in yaegi's "importpath/pkgname" form, e.g. "example.com/host/host") to the exported symbols made available to interpreted code under that import. Only the symbols listed are visible; typically an interface type via reflect.ValueOf((*Iface)(nil)).

Jump to

Keyboard shortcuts

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