plugin

package
v0.3.38 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2024 License: LGPL-2.1 Imports: 11 Imported by: 12

Documentation

Overview

Package plugin 插件,用于开发一些需要使用单例模式设计的功能,例如服务发现、消息队列与日志系统等。

  • 插件主要以组合方式安装在上下文上,用于扩展上下文的能力。
  • 服务与运行时上下文均支持安装插件,注意服务类插件需要支持多线程并发,运行时类插件仅需支持单线程即可。
  • 有一类较为特殊的通用类插件,指在服务与运行时上下文均可安装的插件。

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPlugin = fmt.Errorf("%w: plugin", exception.ErrCore) // 插件错误
)

Functions

func Install

func Install[T any](provider PluginProvider, plugin T, name ...string)

Install 安装插件

func Uninstall

func Uninstall(provider PluginProvider, name string)

Uninstall 卸载插件

func UnsafePluginBundle deprecated

func UnsafePluginBundle(pluginBundle PluginBundle) _UnsafePluginBundle

Deprecated: UnsafePluginBundle 访问插件包的内部方法

func UnsafePluginStatus deprecated added in v0.3.38

func UnsafePluginStatus(status PluginStatus) _UnsafePluginStatus

Deprecated: UnsafePluginStatus 访问插件状态信息的内部方法

func Using

func Using[T any](provider PluginProvider, name string) T

Using 使用插件

Types

type PluginBundle

type PluginBundle interface {
	PluginProvider

	// Install 安装插件,不设置插件名称时,将会使用插件实例名称作为插件名称
	Install(pluginFace iface.FaceAny, name ...string)
	// Uninstall 卸载插件
	Uninstall(name string)
	// Get 获取插件
	Get(name string) (PluginStatus, bool)
	// Range 遍历所有已注册的插件
	Range(fun generic.Func1[PluginStatus, bool])
	// ReversedRange 反向遍历所有已注册的插件
	ReversedRange(fun generic.Func1[PluginStatus, bool])
	// contains filtered or unexported methods
}

PluginBundle 插件包

func NewPluginBundle

func NewPluginBundle() PluginBundle

NewPluginBundle 创建插件包

type PluginProvider

type PluginProvider interface {
	// GetPluginBundle 获取插件包
	GetPluginBundle() PluginBundle
}

PluginProvider 插件提供者

type PluginState added in v0.3.34

type PluginState int8

PluginState 插件状态

const (
	PluginState_Loaded   PluginState = iota // 已加载
	PluginState_Active                      // 已激活
	PluginState_Inactive                    // 未激活
)

func (PluginState) String added in v0.3.34

func (i PluginState) String() string

type PluginStatus added in v0.3.34

type PluginStatus interface {

	// Name 插件名称
	Name() string
	// InstanceFace 插件实例
	InstanceFace() iface.FaceAny
	// Reflected 插件反射值
	Reflected() reflect.Value
	// State 状态
	State() PluginState
	// contains filtered or unexported methods
}

PluginStatus 插件状态信息

Jump to

Keyboard shortcuts

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