plugin

package
v0.0.0-...-d68a214 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package plugin action registry for unified action management

Package plugin type definitions and helper functions

Index

Constants

This section is empty.

Variables

ProviderSet provides plugin layer related dependencies

Functions

func GetPluginConfig

func GetPluginConfig() map[string]any

GetPluginConfig 获取插件配置(线程安全)

func GetPluginTypeDescription

func GetPluginTypeDescription(t PluginType) string

GetPluginTypeDescription returns a description for a plugin type

func IsValidPluginType

func IsValidPluginType(t string) bool

IsValidPluginType checks if a plugin type is valid

func ListPlugins

func ListPlugins() map[string]Plugin

ListPlugins 列出所有已注册的插件实例 供 Manager 从全局注册表加载插件使用

func LoadPluginConfig

func LoadPluginConfig(configPath string) (map[string]any, error)

LoadPluginConfig 加载插件配置文件 configPath 是配置文件路径,如果为空则使用默认路径

func LoadPluginConfigFromDir

func LoadPluginConfigFromDir(confDir string) (map[string]any, error)

LoadPluginConfigFromDir 从配置目录加载插件配置 会在目录中查找 plugins.toml 文件

func PluginTypeString

func PluginTypeString(pt PluginType) string

PluginTypeString returns the string representation of PluginType

func PluginTypeToString

func PluginTypeToString(pt PluginType) string

PluginTypeToString converts PluginType enum to string

func Register

func Register(plugin Plugin)

Register 注册一个插件 插件应该在init函数中调用此函数进行注册 如果注册失败(插件为nil、名称为空或同名插件已存在),会panic

func ValidatePluginType

func ValidatePluginType(pt PluginType) error

ValidatePluginType validates the PluginType

Types

type ActionHandler

type ActionHandler func(params json.RawMessage, opts json.RawMessage) (json.RawMessage, error)

ActionHandler is a function that handles a specific action params: action-specific parameters (JSON) opts: optional overrides (JSON, e.g., timeout, workdir, env) Returns: action result (JSON) and error

type ActionInfo

type ActionInfo struct {
	// Name is the action name (e.g., "send", "build", "clone")
	Name string `json:"name"`
	// Description describes what the action does
	Description string `json:"description"`
	// Handler is the function that handles this action
	Handler ActionHandler `json:"-"`
	// ParamsSchema is optional JSON schema for parameters validation
	Args json.RawMessage `json:"args,omitempty"`
	// ResultSchema is optional JSON schema for result validation
	Returns json.RawMessage `json:"returns,omitempty"`
}

ActionInfo contains metadata about an action

type ActionRegistry

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

ActionRegistry manages action handlers for plugins Provides unified action routing, extensibility, and multi-language support

func NewActionRegistry

func NewActionRegistry() *ActionRegistry

NewActionRegistry creates a new action registry

func (*ActionRegistry) Clear

func (r *ActionRegistry) Clear()

Clear removes all registered actions

func (*ActionRegistry) Count

func (r *ActionRegistry) Count() int

Count returns the number of registered actions

func (*ActionRegistry) Execute

func (r *ActionRegistry) Execute(action string, params json.RawMessage, opts json.RawMessage) (json.RawMessage, error)

Execute executes an action by name This is the unified entry point for all plugin operations

func (*ActionRegistry) Get

func (r *ActionRegistry) Get(name string) (*ActionInfo, bool)

Get retrieves an action handler by name

func (*ActionRegistry) GetMetadata

func (r *ActionRegistry) GetMetadata(action string) (json.RawMessage, bool)

GetMetadata retrieves metadata for an action

func (*ActionRegistry) ListActionInfos

func (r *ActionRegistry) ListActionInfos() []*ActionInfo

ListActionInfos returns detailed information about all registered actions

func (*ActionRegistry) ListActions

func (r *ActionRegistry) ListActions() []string

ListActions returns a list of all registered action names

func (*ActionRegistry) Register

func (r *ActionRegistry) Register(info *ActionInfo) error

Register registers an action handler If an action with the same name already exists, it will be replaced

func (*ActionRegistry) RegisterFunc

func (r *ActionRegistry) RegisterFunc(name, description string, handler ActionHandler) error

RegisterFunc registers an action handler using a function This is a convenience method for simple action handlers

func (*ActionRegistry) SetMetadata

func (r *ActionRegistry) SetMetadata(action string, metadata json.RawMessage) error

SetMetadata sets additional metadata for an action

func (*ActionRegistry) Unregister

func (r *ActionRegistry) Unregister(name string)

Unregister removes an action handler

type Manager

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

Manager 是插件管理器 负责管理所有插件的生命周期,包括注册、初始化、健康检查等

func NewManager

func NewManager(config *ManagerConfig) *Manager

NewManager 创建新的插件管理器

func ProvidePluginManager

func ProvidePluginManager(pluginConfigs map[string]any) *Manager

ProvidePluginManager provides plugin manager instance pluginConfigs 是从配置文件加载的插件配置

func (*Manager) Clear

func (m *Manager) Clear() error

Close 关闭管理器

func (*Manager) Count

func (m *Manager) Count() int

Count 返回已注册插件的数量

func (*Manager) GetPlugin

func (m *Manager) GetPlugin(name string) (Plugin, error)

GetPlugin 获取一个插件

func (*Manager) GetPluginInfo

func (m *Manager) GetPluginInfo(name string) (*PluginInfo, error)

GetPluginInfo 获取插件信息

func (*Manager) HealthCheck

func (m *Manager) HealthCheck() map[string]bool

HealthCheck 执行健康检查

func (*Manager) ListPluginNames

func (m *Manager) ListPluginNames() []string

ListPluginNames 列出所有插件名称

func (*Manager) ListPlugins

func (m *Manager) ListPlugins() map[string]*PluginInfo

ListPlugins 列出所有插件的信息

func (*Manager) RegisterPlugin

func (m *Manager) RegisterPlugin(name string, plugin Plugin, config *RuntimePluginConfig) error

RegisterPlugin 注册一个插件 name: 插件名称(必须与插件自己返回的Name()一致) plugin: 插件实例 config: 插件运行时配置

func (*Manager) RegisterPluginsFromRegistry

func (m *Manager) RegisterPluginsFromRegistry(pluginConfigs map[string]any) error

RegisterPluginsFromRegistry 从全局注册表注册所有插件 这个方法会从全局注册表中获取所有已注册的插件并初始化它们 pluginConfigs 是从配置文件读取的插件配置,格式为 map[插件名称]配置对象

func (*Manager) SafeExecute

func (m *Manager) SafeExecute(pluginName string, action string, params json.RawMessage, opts json.RawMessage) (result json.RawMessage, err error)

SafeExecute 执行插件操作

func (*Manager) StartHeartbeat

func (m *Manager) StartHeartbeat(interval time.Duration)

StartHeartbeat 启动心跳检查(兼容性方法,直接内存插件不需要心跳)

func (*Manager) UnregisterPlugin

func (m *Manager) UnregisterPlugin(name string) error

UnregisterPlugin 取消注册一个插件

type ManagerConfig

type ManagerConfig struct {
	// 超时时间
	Timeout time.Duration
	// 最大重试次数
	MaxRetries int
}

ManagerConfig 是插件管理器的配置

type Plugin

type Plugin interface {
	// Name 返回插件名称
	Name() string

	// Description 返回插件描述
	Description() string

	// Version 返回插件版本
	Version() string

	// Type 返回插件类型
	Type() PluginType

	// Author 返回插件作者
	Author() string

	// Repository 返回插件仓库地址
	Repository() string

	// Init 初始化插件,config 是插件的配置信息(JSON格式)
	Init(config json.RawMessage) error

	// Execute 执行插件操作
	// action: 操作名称(如 "send", "build", "clone")
	// params: 操作参数(JSON格式)
	// opts: 可选参数(JSON格式,如超时、工作目录、环境变量等)
	// 返回: 操作结果(JSON格式)和错误
	Execute(action string, params json.RawMessage, opts json.RawMessage) (json.RawMessage, error)

	// Cleanup 清理插件资源(可选实现)
	Cleanup() error
}

Plugin 是插件必须实现的接口 所有插件都需要实现这个接口才能被注册和使用

type PluginBase

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

PluginBase provides a base implementation for plugins using ActionRegistry Plugins can embed this struct and register their actions during Init

func NewPluginBase

func NewPluginBase() *PluginBase

NewPluginBase creates a new plugin base with action registry

func (*PluginBase) Execute

func (p *PluginBase) Execute(action string, params json.RawMessage, opts json.RawMessage) (json.RawMessage, error)

Execute executes an action using the registry This is the unified entry point for all plugin operations

func (*PluginBase) Registry

func (p *PluginBase) Registry() *ActionRegistry

Registry returns the action registry

type PluginInfo

type PluginInfo struct {
	Name        string     `json:"name"`
	Description string     `json:"description"`
	Version     string     `json:"version"`
	Type        PluginType `json:"type"`
	Author      string     `json:"author,omitempty"`
	Homepage    string     `json:"homepage,omitempty"`
}

PluginInfo 包含插件的元信息

type PluginType

type PluginType int32

PluginType 插件类型枚举

const (
	// TypeUnspecified 未指定的插件类型
	TypeUnspecified PluginType = 0
	// TypeSource Source插件类型
	TypeSource PluginType = 1
	// TypeBuild Build插件类型
	TypeBuild PluginType = 2
	// TypeTest Test插件类型
	TypeTest PluginType = 3
	// TypeDeploy Deploy插件类型
	TypeDeploy PluginType = 4
	// TypeSecurity Security插件类型
	TypeSecurity PluginType = 5
	// TypeNotify Notify插件类型
	TypeNotify PluginType = 6
	// TypeApproval Approval插件类型
	TypeApproval PluginType = 7
	// TypeStorage Storage插件类型
	TypeStorage PluginType = 8
	// TypeAnalytics Analytics插件类型
	TypeAnalytics PluginType = 9
	// TypeIntegration Integration插件类型
	TypeIntegration PluginType = 10
	// TypeCustom Custom插件类型
	TypeCustom PluginType = 11
)

func AllPluginTypes

func AllPluginTypes() []PluginType

AllPluginTypes returns all supported plugin types

func StringToPluginType

func StringToPluginType(s string) PluginType

StringToPluginType converts string to PluginType enum

type RuntimePluginConfig

type RuntimePluginConfig struct {
	Name        string            `json:"name"`
	Version     string            `json:"version"`
	Type        string            `json:"type"`
	Config      json.RawMessage   `json:"config"`
	Environment map[string]string `json:"environment,omitempty"`
	TaskID      string            `json:"task_id,omitempty"`
}

RuntimePluginConfig 表示插件的运行时配置

Jump to

Keyboard shortcuts

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