service

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 22 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoHookPlugin = gerror.New("未注册对应的Hook插件")

ErrNoHookPlugin 未注册对应 Hook 插件(调用方回退默认实现)

Functions

func HasHook

func HasHook(hook string) bool

HasHook 是否有已启用的 Hook 插件

func InitUploadHook

func InitUploadHook()

InitUploadHook 注册上传钩子:存在启用中的 upload Hook 插件时接管上传 (对应 cool-admin 中 Hook 插件替换默认上传实现的行为)

func Invoke

func Invoke(ctx context.Context, key, method string, params ...interface{}) (interface{}, error)

Invoke 调用指定插件方法(跨插件调用入口,插件 SDK pluginService.Invoke 走此路径)

func InvokeHook

func InvokeHook(ctx context.Context, hook, method string, args ...interface{}) (interface{}, error)

InvokeHook 调用 Hook 插件方法;未注册返回 ErrNoHookPlugin(调用方回退默认实现)

func LoadProcessPlugin

func LoadProcessPlugin(keyName, hook, binPath string, info *PluginInfoData) error

LoadProcessPlugin 加载并注册插件可执行程序 singleton=true 常驻进程;false 每次调用拉起进程(对齐参考实现的实例语义)

func ParseZip

func ParseZip(raw []byte) (*pluginZipData, error)

ParseZip 解析插件 ZIP 包:plugin.json / readme / logo / 可执行文件

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 GetPluginCenter

func GetPluginCenter() *PluginCenter

GetPluginCenter 获取插件中心实例

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"`
	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

type PluginService struct {
	*v.Service
}

PluginService 插件信息服务(参照 cool-admin-midway PluginService; 插件本体为可执行程序,经 stdio JSON-RPC 与宿主通信)

func NewPluginService

func NewPluginService() *PluginService

NewPluginService 创建插件服务实例

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) InitAll

func (s *PluginService) InitAll()

InitAll 启动初始化:加载全部启用插件

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 互斥)

Jump to

Keyboard shortcuts

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