plugin

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListScripts added in v0.28.0

func ListScripts() []string

ListScripts returns the names of all loaded script plugins (without the "script:" prefix).

func LoadScripts added in v0.28.0

func LoadScripts(dir string) (int, error)

LoadScripts loads all executable scripts from a directory as command plugins. Scripts are registered as custom commands that can be invoked via `tinker plugin run <name>`.

func RunScript added in v0.28.0

func RunScript(name string, args []string) error

RunScript executes a registered script plugin.

Types

type Context added in v0.28.0

type Context struct {
	Data map[string]interface{}
}

Context carries data to and from hook handlers.

func NewContext added in v0.28.0

func NewContext() *Context

NewContext creates an empty hook context.

func (*Context) Get added in v0.28.0

func (c *Context) Get(key string) interface{}

Get retrieves a value from the context.

func (*Context) GetString added in v0.28.0

func (c *Context) GetString(key string) string

GetString retrieves a string value from the context.

func (*Context) Set added in v0.28.0

func (c *Context) Set(key string, val interface{})

Set stores a value in the context.

type Handler added in v0.28.0

type Handler func(*Context) error

Handler is a function that handles a hook invocation. It can modify the context and optionally return an error to abort the chain.

type Hook added in v0.28.0

type Hook string

Hook represents a named entry point where plugins can register behavior.

const (
	// HookPreDBQuery runs before a database query is executed.
	HookPreDBQuery Hook = "pre_db_query"
	// HookPostDBQuery runs after a database query is executed.
	HookPostDBQuery Hook = "post_db_query"
	// HookPreAPIRequest runs before an API request is sent.
	HookPreAPIRequest Hook = "pre_api_request"
	// HookPostAPIRequest runs after an API response is received.
	HookPostAPIRequest Hook = "post_api_request"
	// HookPreGRPCCall runs before a gRPC call.
	HookPreGRPCCall Hook = "pre_grpc_call"
	// HookPostGRPCCall runs after a gRPC call.
	HookPostGRPCCall Hook = "post_grpc_call"
	// HookInit runs during tinker init after auto-detection.
	HookInit Hook = "init"
)

type Info added in v0.28.0

type Info struct {
	Name        string
	Description string
	Version     string
	Hooks       []string
}

Info provides metadata about a loaded plugin.

type Plugin added in v0.28.0

type Plugin struct {
	Name        string
	Description string
	Version     string
	Meta        map[string]interface{}
	// contains filtered or unexported fields
}

Plugin represents a loaded plugin with its metadata and registered hooks.

func New added in v0.28.0

func New(name string) *Plugin

New creates a new plugin with the given name.

func (*Plugin) On added in v0.28.0

func (p *Plugin) On(hook Hook, handler Handler)

On registers a handler for a specific hook.

type Registry added in v0.28.0

type Registry struct {
	// contains filtered or unexported fields
}

Registry manages all loaded plugins and dispatches hooks.

func Global added in v0.28.0

func Global() *Registry

Global returns the global plugin registry.

func NewRegistry added in v0.28.0

func NewRegistry() *Registry

NewRegistry creates a new empty registry.

func (*Registry) Dispatch added in v0.28.0

func (r *Registry) Dispatch(hook Hook, ctx *Context) error

Dispatch sends a hook event to all registered handlers across all plugins. Handlers are called in plugin registration order. If any handler returns an error, dispatch stops and returns that error.

func (*Registry) Get added in v0.28.0

func (r *Registry) Get(name string) (*Plugin, bool)

Get returns a plugin by name.

func (*Registry) List added in v0.28.0

func (r *Registry) List() []string

List returns all registered plugin names, sorted.

func (*Registry) ListPlugins added in v0.28.0

func (r *Registry) ListPlugins() []Info

ListPlugins returns all registered plugins with their info.

func (*Registry) Register added in v0.28.0

func (r *Registry) Register(p *Plugin) error

Register adds a plugin to the registry.

func (*Registry) Unregister added in v0.28.0

func (r *Registry) Unregister(name string)

Unregister removes a plugin from the registry.

Jump to

Keyboard shortcuts

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