Documentation
¶
Index ¶
- Variables
- func HasHook(hook string) bool
- func InitUploadHook()
- func Invoke(ctx context.Context, key, method string, params ...interface{}) (interface{}, error)
- func InvokeHook(ctx context.Context, hook, method string, args ...interface{}) (interface{}, error)
- func LoadProcessPlugin(keyName, hook string, cmd pluginCmd, info *PluginInfoData) error
- func ParseZip(raw []byte) (*pluginZipData, error)
- type CheckResult
- type PluginCenter
- type PluginInfoData
- type PluginInstance
- type PluginService
- func (s *PluginService) AddOrUpdate(ctx context.Context, id uint) error
- func (s *PluginService) Check(raw []byte) (*CheckResult, error)
- func (s *PluginService) Delete(ctx context.Context, ids []int) error
- func (s *PluginService) InitAll()
- func (s *PluginService) Install(ctx context.Context, raw []byte, force bool) (*CheckResult, error)
- func (s *PluginService) ReloadKey(key string)
- func (s *PluginService) ServiceDelete(ctx context.Context, req *v.DeleteReq) (data interface{}, err error)
- func (s *PluginService) ServiceUpdate(ctx context.Context, req *v.UpdateReq) (data interface{}, err error)
Constants ¶
This section is empty.
Variables ¶
var ErrNoHookPlugin = gerror.New("未注册对应的Hook插件")
ErrNoHookPlugin 未注册对应 Hook 插件(调用方回退默认实现)
Functions ¶
func InitUploadHook ¶
func InitUploadHook()
InitUploadHook 注册上传钩子:存在启用中的 upload Hook 插件时接管上传 (对应 cool-admin 中 Hook 插件替换默认上传实现的行为)
func InvokeHook ¶
InvokeHook 调用 Hook 插件方法;未注册返回 ErrNoHookPlugin(调用方回退默认实现)
func LoadProcessPlugin ¶
func LoadProcessPlugin(keyName, hook string, cmd pluginCmd, info *PluginInfoData) error
LoadProcessPlugin 加载并注册插件进程 singleton=true 常驻进程;false 每次调用拉起进程(对齐参考实现的实例语义)
Types ¶
type CheckResult ¶
type CheckResult struct {
Type int `json:"type"` // 0-信息不完整 1-已存在(覆盖) 2-同名Hook插件已启用 3-检查通过
Message string `json:"message"`
}
CheckResult 安装前检查结果
type PluginCenter ¶
type PluginCenter struct {
// contains filtered or unexported fields
}
PluginCenter 插件中心(单例注册表,对应参考实现 PluginCenterService)
func (*PluginCenter) GetInstance ¶
func (c *PluginCenter) GetInstance(key string) PluginInstance
GetInstance 获取插件实例
func (*PluginCenter) GetPluginInfo ¶
func (c *PluginCenter) GetPluginInfo(key string) *PluginInfoData
GetPluginInfo 获取插件信息
func (*PluginCenter) Register ¶
func (c *PluginCenter) Register(key string, instance PluginInstance, info *PluginInfoData)
Register 注册插件实例(key:普通插件用 keyName,Hook 插件用 hook 名)
func (*PluginCenter) Remove ¶
func (c *PluginCenter) Remove(key string, isHook bool)
Remove 移除插件并停止其进程
type PluginInfoData ¶
type PluginInfoData struct {
Name string `json:"name"`
Key string `json:"key"`
Hook string `json:"hook"`
Singleton bool `json:"singleton"`
Version string `json:"version"`
Description string `json:"description"`
Author string `json:"author"`
Logo string `json:"logo"`
Readme string `json:"readme"`
BaseDir string `json:"baseDir"`
Config map[string]interface{} `json:"config"`
}
PluginInfoData 插件信息(对应 pluginsdk.PluginInfo / 参考实现 PluginInfo)
func BuildPluginInfoData ¶
func BuildPluginInfoData(row map[string]interface{}, baseDir string) *PluginInfoData
BuildPluginInfoData 从数据库行构造插件信息(含 @env 多环境配置解析)
type PluginInstance ¶
type PluginInstance interface {
// Invoke 调用插件方法
Invoke(method string, args ...interface{}) (interface{}, error)
}
PluginInstance 插件实例抽象(可执行进程 / 内置实现统一派发)
type PluginService ¶
PluginService 插件信息服务(参照 cool-admin-midway PluginService; 插件本体为可执行程序,经 stdio JSON-RPC 与宿主通信)
func (*PluginService) AddOrUpdate ¶
func (s *PluginService) AddOrUpdate(ctx context.Context, id uint) error
AddOrUpdate 新增或更新后联动热加载/移除
func (*PluginService) Check ¶
func (s *PluginService) Check(raw []byte) (*CheckResult, error)
Check 安装前检查
func (*PluginService) Delete ¶
func (s *PluginService) Delete(ctx context.Context, ids []int) error
Delete 删除插件(不走回收站)
func (*PluginService) Install ¶
func (s *PluginService) Install(ctx context.Context, raw []byte, force bool) (*CheckResult, error)
Install 安装插件(ZIP 包;force 跳过检查)
func (*PluginService) ReloadKey ¶
func (s *PluginService) ReloadKey(key string)
ReloadKey 重新加载单个插件(启用/安装后热更新:起进程并 ready 握手)
func (*PluginService) ServiceDelete ¶
func (s *PluginService) ServiceDelete(ctx context.Context, req *v.DeleteReq) (data interface{}, err error)
ServiceDelete 删除插件(不走回收站,连同安装目录清理)
func (*PluginService) ServiceUpdate ¶
func (s *PluginService) ServiceUpdate(ctx context.Context, req *v.UpdateReq) (data interface{}, err error)
ServiceUpdate 更新后联动热加载/移除(同 Hook 互斥)