plugin

package module
v0.0.0-...-107c718 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Type_Plugin  = "Plugin"  //插件对象
	Type_Topic   = "Topic"   //主题对象
	Type_Service = "Service" //主体对象,名称可忽略
	Type_Other   = "Other"   //其他对象,预留
)

发送者和接收者的值为json格式,格式如下:

View Source
const (
	Command_Exit        = "Service.Exit"           //退出系统
	Command_RegTopic    = "Service.RegTopic"       //执行主题命令,注册和反注册
	Command_Result      = "Service.ExecuteResult"  //执行来自于UDP传送过来的命令
	Command_TransPlugin = "Service.TransPlugin"    //执行插件命令
	Command_Service     = "Service.ExecuteService" //执行主体命令
	Command_DB          = "Service.ExecuteDB"      //执行数据库命令
	Command_Log         = "Service.Log"            //日志命令
)

Variables

This section is empty.

Functions

func GetMessageID

func GetMessageID() uint64

Types

type AppObj

type AppObj struct {
	DB      *sql.DB
	DataBus chan *PluginMsg
}

func NewAppObj

func NewAppObj(db *sql.DB) *AppObj

type Object

type Object struct {
	Type string //类型,采用上述字符串常量,以Type_打头
	Name string //名称
}

type Plugin

type Plugin interface {
	// 初始化插件,带入插件消息通道,该通道由服务框架创建,各插件调用
	Init(obj *AppObj) error
	// 启动插件
	Start() error
	// 停止插件
	Stop() error
	// 获取插件元信息
	Meta() *PluginMeta
	//接收消息,插件内部传送消息
	Receiver(*PluginMsg)
}

Plugin 定义插件标准接口

type PluginMeta

type PluginMeta struct {
	Name    string //插件名称,具有唯一性
	Version string //版本
	Author  string //作者
}

PluginMeta 插件元数据

func NewPluginMeta

func NewPluginMeta(name, version, author string) *PluginMeta

type PluginMsg

type PluginMsg struct {
	ID       uint64   //消息ID
	Cmd      string   //命令,保留以“Service.“开头的命令
	Sender   Object   //发送者
	Receiver []Object //接收者,可以多个
	Option   string   //附加数据
	Data     []byte   //传送的数据体,以字节方式传递
}

插件之间传递消息

Jump to

Keyboard shortcuts

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