plugin

package
v0.0.0-...-a9bd8d8 Latest Latest
Warning

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

Go to latest
Published: May 15, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package plugin 本包统一插件的机制

Index

Constants

View Source
const (
	// SUPPORT_ARGS 命令行参数支持
	SUPPORT_ARGS uint32 = 0x0
	// SUPPORT_LOGGER 所有的日志支持
	SUPPORT_LOGGER    uint32 = 0x10
	SUPPORT_STDLOG    uint32 = 0x12
	SUPPORT_ACCESSLOG uint32 = 0x14
	SUPPORT_ERRORLOG  uint32 = 0x16
	// SUPPORT_CONFIG_OBJ 所有配置文件功能的支持
	SUPPORT_CONFIG_OBJ uint32 = 0x100
	// SUPPORT_RAW_CONFIG 原生的配置文件接口,原型:io.ReadWriteCloser
	SUPPORT_RAW_CONFIG uint32 = 0x110
	// SUPPORT_RAW_FILE 原生的*os.File支持
	SUPPORT_RAW_FILE uint32 = 0x120
)

插件需要的支持

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {

	// 原生的资源对象
	RawSource *Source
	// contains filtered or unexported fields
}

func NewContext

func NewContext() *Context

func (*Context) GetState

func (c *Context) GetState() Type

func (*Context) RangeAllPlugin

func (c *Context) RangeAllPlugin(fn func(k int, v Plugin))

RangeAllPlugin 遍历所有注册的插件

func (*Context) RangeArgsPlugin

func (c *Context) RangeArgsPlugin(fn func(k int, v Plugin))

RangeArgsPlugin 遍历支持参数的插件列表

func (*Context) Register

func (c *Context) Register(s string)

func (*Context) RegisterRaw

func (c *Context) RegisterRaw(regPlugin Plugin)

func (*Context) SetState

func (c *Context) SetState(s Type)

type New

type New func() Plugin

New 一些重要的,插件必需要实现的函数类型

type Plugin

type Plugin interface {
	// Start 插件启动时调用的方法
	Start(args []string)
	// Caller 接收到信号时调用的方法
	Caller(single Single)
	// GetName 主程序获取插件的名字
	GetName() string
	// GetType 主程序获取插件的类型
	GetType() Type
	// GetSupport 主程序获取插件需要的支持
	GetSupport() []uint32
	// SetSource 设置插件需要的Source
	SetSource(source *Source)
}

Plugin 插件的插入要实现的接口

type Single

type Single int
const (
	// Exit 退出
	Exit Single = iota
)

插件接收的信号

type Source

type Source struct {
	Config *config.AutoGenerated
	// 原生配置文件接口
	RawConfig io.ReadWriteCloser
	// 原生文件
	RawFile   *os.File
	AccessLog bilog.Logger
	ErrorLog  bilog.Logger
	StdLog    bilog.Logger
}

Source 插件使用到的资源定义 根据需求注册

func (*Source) GetConfigReadWriter

func (s *Source) GetConfigReadWriter() io.ReadWriter

func (*Source) GetConfigReader

func (s *Source) GetConfigReader() io.Reader

func (*Source) GetConfigWriter

func (s *Source) GetConfigWriter() io.Writer

type Type

type Type int
const (
	Init      Type = 0 // 初始化时调用的插件,程序运行周期只会调用一次
	BCollect  Type = 1 // 需要搜集备份数据时调用的插件
	BHandle   Type = 2 // 需要处理备份的数据时调用的插件
	BCallBack Type = 3 // 处理完备份数据时调用的插件
)

描述插件生命周期的常量

Jump to

Keyboard shortcuts

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