plugin

package
v0.12.21 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: MIT Imports: 3 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidPluginCreator    = errors.New("invalid plugin creator")
	ErrInvalidPluginCfgCreator = errors.New("invalid plugin cfg creator")
)

Functions

func Create

func Create[T any, P Plugin](typ T) P

func CreateCfg

func CreateCfg[T any](typ T) any

func CreateWithCfg

func CreateWithCfg[T any, P Plugin](typ T, cfg any) P

创建一个注册的Plugin 这里不返回错误而是直接panic的原因是: Create函数只是把plugin创建出来,并把cfg设置到plugin中对应的一个字段里。 这里的panic分为两种情况 1. plugin不存在,说明没有注册,大部分情况是没有调用Reg 2. cfg设置失败,说明plugin本身定义的有问题 这两种情况下说明代码本身有问题,所以直接panic.

func Reg added in v0.9.19

func Reg[T any, P Plugin](typ T, creator Creator[P], cfgCreator CfgCreator[any])

推荐自定义plugin的类型,不要直接使用基础类型,例如 type DaemonType string const DaemonTypeHttpd DaemonType = "httpd" Reg(DaemonTypeHttpd, func() Daemon { return NewHttpd() }, func() any { return NewHttpdCfg() }).

func SetCfg

func SetCfg[C any](p any, cfg C)

Types

type CfgCreator

type CfgCreator[C any] func() C

type CfgSetter

type CfgSetter[C any] interface {
	SetCfg(cfg C)
}

type Creator

type Creator[P Plugin] func() P

type Plugin

type Plugin any

type Type

type Type string

Jump to

Keyboard shortcuts

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