{"modulePath":"github.com/GoCodeAlone/workflow","version":"v0.87.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package dynamic\n\n## Variables\n\n```go\nvar AllowedPackages = map[string]bool{\n\n\t\"fmt\":             true,\n\t\"strings\":         true,\n\t\"strconv\":         true,\n\t\"encoding/json\":   true,\n\t\"encoding/xml\":    true,\n\t\"encoding/csv\":    true,\n\t\"encoding/base64\": true,\n\t\"context\":         true,\n\t\"time\":            true,\n\t\"math\":            true,\n\t\"math/rand\":       true,\n\t\"sort\":            true,\n\t\"sync\":            true,\n\t\"sync/atomic\":     true,\n\t\"errors\":          true,\n\t\"io\":              true,\n\t\"bytes\":           true,\n\t\"bufio\":           true,\n\t\"unicode\":         true,\n\t\"unicode/utf8\":    true,\n\t\"regexp\":          true,\n\t\"path\":            true,\n\t\"net/url\":         true,\n\t\"net/http\":        true,\n\t\"log\":             true,\n\t\"maps\":            true,\n\t\"slices\":          true,\n\t\"crypto/aes\":      true,\n\t\"crypto/cipher\":   true,\n\t\"crypto/rand\":     true,\n\t\"crypto/sha256\":   true,\n\t\"crypto/hmac\":     true,\n\t\"crypto/md5\":      true,\n\t\"encoding/hex\":    true,\n\t\"hash\":            true,\n\t\"html\":            true,\n\t\"html/template\":   true,\n\t\"text/template\":   true,\n}\n```\nAllowedPackages defines the standard library packages that dynamically loaded components are permitted to import. Packages not in this list will be rejected during source validation.\n\n```go\nvar BlockedPackages = map[string]bool{\n\t\"os/exec\":        true,\n\t\"syscall\":        true,\n\t\"unsafe\":         true,\n\t\"plugin\":         true,\n\t\"runtime/debug\":  true,\n\t\"reflect\":        true,\n\t\"os\":             true,\n\t\"net\":            true,\n\t\"crypto/tls\":     true,\n\t\"debug/elf\":      true,\n\t\"debug/macho\":    true,\n\t\"debug/pe\":       true,\n\t\"debug/plan9obj\": true,\n}\n```\nBlockedPackages defines packages that are explicitly forbidden for security reasons.\n\n## Functions\n\n```go\nfunc ApplyDefaults(contract *FieldContract, params map[string]any) map[string]any\n```\nApplyDefaults fills in default values from the contract for any missing optional fields in params. It returns a new map with defaults applied (does not mutate the original).\n\n```go\nfunc ExecuteWithLimits(\n\tctx context.Context,\n\tcomp *DynamicComponent,\n\tparams map[string]any,\n\tlimits ResourceLimits,\n) (map[string]any, error)\n```\nExecuteWithLimits wraps a DynamicComponent's Execute call with resource enforcement: a context-based timeout and output size validation.\n\n```go\nfunc IsPackageAllowed(pkg string) bool\n```\nIsPackageAllowed checks if a given import path is permitted in dynamic components.\n\n```go\nfunc ValidateInputs(contract *FieldContract, params map[string]any) error\n```\nValidateInputs checks params against the given contract. It returns an error describing all missing required fields and type mismatches found.\n\n```go\nfunc ValidateSource(source string) error\n```\nValidateSource performs a basic syntax check and verifies that only allowed packages are imported.\n\n## Types\n\n```go\ntype APIHandler struct {\n\t// contains filtered or unexported fields\n}\n```\nAPIHandler exposes HTTP endpoints for managing dynamic components.\n\n```go\nfunc NewAPIHandler(loader *Loader, registry *ComponentRegistry) *APIHandler\n```\nNewAPIHandler creates a new API handler.\n\n```go\nfunc (h *APIHandler) HandleComponentByID(w http.ResponseWriter, r *http.Request)\n```\nHandleComponentByID handles GET/PUT/DELETE for a component by ID. The ID is extracted as the last path segment, making this work with any URL prefix (e.g. /api/dynamic/components/{id} or /api/v1/admin/components/{id}).\n\n```go\nfunc (h *APIHandler) HandleComponents(w http.ResponseWriter, r *http.Request)\n```\nHandleComponents handles GET/POST /api/dynamic/components.\n\n```go\nfunc (h *APIHandler) RegisterRoutes(mux *http.ServeMux)\n```\nRegisterRoutes registers the dynamic component API routes on the given mux.\n\n```go\nfunc (h *APIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)\n```\nServeHTTP implements http.Handler for config-driven delegate dispatch. It routes to HandleComponents or HandleComponentByID based on the path.\n\n```go\ntype ComponentInfo struct {\n\tID       string          `json:\"id\"`\n\tName     string          `json:\"name\"`\n\tSource   string          `json:\"source,omitempty\"`\n\tStatus   ComponentStatus `json:\"status\"`\n\tLoadedAt time.Time       `json:\"loaded_at\"`\n\tError    string          `json:\"error,omitempty\"`\n}\n```\nComponentInfo holds metadata about a loaded dynamic component.\n\n```go\ntype ComponentRegistry struct {\n\t// contains filtered or unexported fields\n}\n```\nComponentRegistry tracks all dynamically loaded components. It is safe for concurrent access.\n\n```go\nfunc NewComponentRegistry() *ComponentRegistry\n```\nNewComponentRegistry creates an empty registry.\n\n```go\nfunc (r *ComponentRegistry) Count() int\n```\nCount returns the number of registered components.\n\n```go\nfunc (r *ComponentRegistry) Get(id string) (*DynamicComponent, bool)\n```\nGet retrieves a component by ID.\n\n```go\nfunc (r *ComponentRegistry) List() []ComponentInfo\n```\nList returns info for all registered components.\n\n```go\nfunc (r *ComponentRegistry) ListNames() []string\n```\nListNames returns the IDs of all registered components.\n\n```go\nfunc (r *ComponentRegistry) Register(id string, component *DynamicComponent) error\n```\nRegister adds or replaces a component in the registry.\n\n```go\nfunc (r *ComponentRegistry) Unregister(id string) error\n```\nUnregister removes a component from the registry.\n\n```go\ntype ComponentStatus string\n```\nComponentStatus describes the lifecycle state of a dynamic component.\n\n```go\nconst (\n\tStatusUnloaded    ComponentStatus = \"unloaded\"\n\tStatusLoaded      ComponentStatus = \"loaded\"\n\tStatusInitialized ComponentStatus = \"initialized\"\n\tStatusRunning     ComponentStatus = \"running\"\n\tStatusStopped     ComponentStatus = \"stopped\"\n\tStatusError       ComponentStatus = \"error\"\n)\n```\n\n```go\ntype ContractRegistry struct {\n\t// contains filtered or unexported fields\n}\n```\nContractRegistry stores field contracts indexed by component name. It is safe for concurrent access.\n\n```go\nfunc NewContractRegistry() *ContractRegistry\n```\nNewContractRegistry creates an empty ContractRegistry.\n\n```go\nfunc (cr *ContractRegistry) Get(name string) (*FieldContract, bool)\n```\nGet retrieves the contract for a component, if one exists.\n\n```go\nfunc (cr *ContractRegistry) List() []string\n```\nList returns all registered component names.\n\n```go\nfunc (cr *ContractRegistry) Register(name string, contract *FieldContract)\n```\nRegister stores a contract for the given component name.\n\n```go\nfunc (cr *ContractRegistry) Unregister(name string)\n```\nUnregister removes a contract for the given component name.\n\n```go\ntype DynamicComponent struct {\n\n\t// Contract holds the field contract extracted from the component, if declared.\n\tContract *FieldContract\n\t// contains filtered or unexported fields\n}\n```\nDynamicComponent wraps Yaegi-interpreted Go code as a workflow component that satisfies the modular.Module interface.\n\n```go\nfunc NewDynamicComponent(id string, pool *InterpreterPool) *DynamicComponent\n```\nNewDynamicComponent creates a new unloaded dynamic component.\n\n```go\nfunc (dc *DynamicComponent) Execute(ctx context.Context, params map[string]any) (map[string]any, error)\n```\nExecute runs the interpreted Execute function. If the component declares a field contract, inputs are validated and defaults applied before execution.\n\n```go\nfunc (dc *DynamicComponent) Info() ComponentInfo\n```\nInfo returns the current component metadata.\n\n```go\nfunc (dc *DynamicComponent) Init(services map[string]any) error\n```\nInit satisfies modular.Module. It delegates to the interpreted Init function.\n\n```go\nfunc (dc *DynamicComponent) LoadFromSource(source string) error\n```\nLoadFromSource compiles and loads Go source code into the component.\n\n```go\nfunc (dc *DynamicComponent) Name() string\n```\nName returns the component name. If interpreted code provides a Name() function, that value is used; otherwise the component ID is returned.\n\n```go\nfunc (dc *DynamicComponent) Source() string\n```\nSource returns the loaded source code.\n\n```go\nfunc (dc *DynamicComponent) Start(ctx context.Context) error\n```\nStart runs the interpreted Start function.\n\n```go\nfunc (dc *DynamicComponent) Stop(ctx context.Context) error\n```\nStop runs the interpreted Stop function.\n\n```go\ntype FieldContract struct {\n\tRequiredInputs map[string]FieldSpec `json:\"required_inputs,omitempty\"`\n\tOptionalInputs map[string]FieldSpec `json:\"optional_inputs,omitempty\"`\n\tOutputs        map[string]FieldSpec `json:\"outputs,omitempty\"`\n}\n```\nFieldContract declares the input/output field requirements for a dynamic component.\n\n```go\nfunc NewFieldContract() *FieldContract\n```\nNewFieldContract creates an empty FieldContract.\n\n```go\ntype FieldSpec struct {\n\tType        FieldType `json:\"type\"`\n\tDescription string    `json:\"description,omitempty\"`\n\tDefault     any       `json:\"default,omitempty\"`\n}\n```\nFieldSpec describes a single field in a contract.\n\n```go\ntype FieldType string\n```\nFieldType describes the expected type of a field in a contract.\n\n```go\nconst (\n\tFieldTypeString FieldType = \"string\"\n\tFieldTypeInt    FieldType = \"int\"\n\tFieldTypeBool   FieldType = \"bool\"\n\tFieldTypeFloat  FieldType = \"float\"\n\tFieldTypeMap    FieldType = \"map\"\n\tFieldTypeSlice  FieldType = \"slice\"\n\tFieldTypeAny    FieldType = \"any\"\n)\n```\n\n```go\ntype InterpreterPool struct {\n\t// contains filtered or unexported fields\n}\n```\nInterpreterPool manages a pool of Yaegi interpreters.\n\n```go\nfunc NewInterpreterPool(opts ...Option) *InterpreterPool\n```\nNewInterpreterPool creates a new pool with optional configuration.\n\n```go\nfunc (p *InterpreterPool) NewInterpreter() (*interp.Interpreter, error)\n```\nNewInterpreter creates a sandboxed Yaegi interpreter with only the allowed standard library symbols loaded.\n\n```go\ntype Loader struct {\n\t// contains filtered or unexported fields\n}\n```\nLoader handles loading dynamic components from various sources.\n\n```go\nfunc NewLoader(pool *InterpreterPool, registry *ComponentRegistry) *Loader\n```\nNewLoader creates a Loader backed by the given pool and registry.\n\n```go\nfunc (l *Loader) LoadFromDirectory(dir string) ([]*DynamicComponent, error)\n```\nLoadFromDirectory scans a directory for .go files and loads each one.\n\n```go\nfunc (l *Loader) LoadFromFile(id, path string) (*DynamicComponent, error)\n```\nLoadFromFile reads a .go file and loads it as a component. The component ID is derived from the filename (without extension) unless the caller provides an explicit id.\n\n```go\nfunc (l *Loader) LoadFromString(id, source string) (*DynamicComponent, error)\n```\nLoadFromString validates, compiles, and registers a component from source.\n\n```go\nfunc (l *Loader) Reload(id, source string) (*DynamicComponent, error)\n```\nReload unloads an existing component and reloads it from new source.\n\n```go\ntype ModuleAdapter struct {\n\t// contains filtered or unexported fields\n}\n```\nModuleAdapter wraps a DynamicComponent as a modular.Module so it can participate in the modular dependency system.\n\n```go\nfunc NewModuleAdapter(component *DynamicComponent) *ModuleAdapter\n```\nNewModuleAdapter creates a new ModuleAdapter wrapping the given component.\n\n```go\nfunc (a *ModuleAdapter) Execute(ctx context.Context, params map[string]any) (map[string]any, error)\n```\nExecute delegates execution to the underlying component.\n\n```go\nfunc (a *ModuleAdapter) Init(app modular.Application) error\n```\nInit initializes the adapter by collecting required services and passing them to the underlying component, then registering provided services.\n\n```go\nfunc (a *ModuleAdapter) Name() string\n```\nName returns the component name.\n\n```go\nfunc (a *ModuleAdapter) ProvidesServices() []modular.ServiceProvider\n```\nProvidesServices returns the services provided by this adapter.\n\n```go\nfunc (a *ModuleAdapter) RequiresServices() []modular.ServiceDependency\n```\nRequiresServices returns the services required by this adapter.\n\n```go\nfunc (a *ModuleAdapter) SetProvides(services []string)\n```\nSetProvides sets the list of service names this adapter provides.\n\n```go\nfunc (a *ModuleAdapter) SetRequires(services []string)\n```\nSetRequires sets the list of service names this adapter requires.\n\n```go\ntype Option func(*InterpreterPool)\n```\nOption configures an InterpreterPool.\n\n```go\nfunc WithAllowedPackages(pkgs map[string]bool) Option\n```\nWithAllowedPackages overrides the default allowed packages list.\n\n```go\nfunc WithGoPath(path string) Option\n```\nWithGoPath sets the GOPATH for interpreters.\n\n```go\ntype PluginWatcher struct {\n\t// contains filtered or unexported fields\n}\n```\nPluginWatcher monitors one or more plugin directories for .go file changes and hot-reloads components. Unlike the base Watcher, it supports watching multiple directories and has a dev mode for relaxed validation.\n\n```go\nfunc NewPluginWatcher(loader *Loader, dirs []string, opts ...PluginWatcherOption) *PluginWatcher\n```\nNewPluginWatcher creates a watcher that monitors plugin directories for changes.\n\n```go\nfunc (w *PluginWatcher) DevMode() bool\n```\nDevMode returns whether development mode is enabled.\n\n```go\nfunc (w *PluginWatcher) Start() error\n```\nStart begins watching all plugin directories for changes.\n\n```go\nfunc (w *PluginWatcher) Stop() error\n```\nStop terminates the watcher.\n\n```go\ntype PluginWatcherOption func(*PluginWatcher)\n```\nPluginWatcherOption configures a PluginWatcher.\n\n```go\nfunc WithDevMode(enabled bool) PluginWatcherOption\n```\nWithDevMode enables development mode which relaxes validation for faster iteration (allows all stdlib imports and skips contract validation).\n\n```go\nfunc WithOnReload(fn func(id string, err error)) PluginWatcherOption\n```\nWithOnReload sets a callback invoked after a plugin is reloaded.\n\n```go\nfunc WithPluginDebounce(d time.Duration) PluginWatcherOption\n```\nWithPluginDebounce sets the debounce duration for file change events.\n\n```go\nfunc WithPluginLogger(l *log.Logger) PluginWatcherOption\n```\nWithPluginLogger sets the logger for the watcher.\n\n```go\ntype ResourceLimits struct {\n\t// MaxExecutionTime is the maximum duration a single Execute call may run.\n\t// Zero means no timeout (not recommended for production).\n\tMaxExecutionTime time.Duration\n\n\t// MaxOutputSize is the maximum number of keys allowed in the Execute output map.\n\t// Zero means unlimited.\n\tMaxOutputSize int\n}\n```\nResourceLimits configures resource constraints for dynamic component execution.\n\n```go\nfunc DefaultResourceLimits() ResourceLimits\n```\nDefaultResourceLimits returns sensible defaults for production use.\n\n```go\nfunc ParseResourceLimitsFromConfig(cfg map[string]any) ResourceLimits\n```\nParseResourceLimitsFromConfig extracts ResourceLimits from a YAML config map.\n\n```go\ntype Watcher struct {\n\t// contains filtered or unexported fields\n}\n```\nWatcher monitors a directory for .go file changes and hot-reloads components.\n\n```go\nfunc NewWatcher(loader *Loader, dir string, opts ...WatcherOption) *Watcher\n```\nNewWatcher creates a file system watcher that automatically reloads components when .go files in the watched directory change.\n\n```go\nfunc (w *Watcher) Start() error\n```\nStart begins watching the directory for changes.\n\n```go\nfunc (w *Watcher) Stop() error\n```\nStop terminates the watcher.\n\n```go\ntype WatcherOption func(*Watcher)\n```\nWatcherOption configures a Watcher.\n\n```go\nfunc WithDebounce(d time.Duration) WatcherOption\n```\nWithDebounce sets the debounce duration for file change events.\n\n```go\nfunc WithLogger(l *log.Logger) WatcherOption\n```\nWithLogger sets the logger for the watcher.\n\n","path":"github.com/GoCodeAlone/workflow/dynamic","name":"dynamic","synopsis":"","isRedistributable":true}
