module

package
v0.0.0-...-80248e1 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreatorFunction

type CreatorFunction func(holder IHolder) IModule

CreatorFunction 定义模块创建器函数类型

将持有者传递给模块

type Factory

type Factory struct {
	// contains filtered or unexported fields
}

Factory 模块工厂结构体

采用数组的方式, 索引:模块类型, 值:模块元素的指针

func NewFactory

func NewFactory(capacity uint32) *Factory

NewFactory 创建新的工厂实例

参数: capacity - 模块创建器数组的初始容量
e.g.: 0: a模块, 1: b模块, 2: c模块 => 传递 capacity = 3

func (*Factory) CreateAllModule

func (p *Factory) CreateAllModule(holder IHolder)

CreateAllModule 创建所有模块

func (*Factory) Foreach

func (p *Factory) Foreach(callback func(element *Module))

Foreach 遍历所有模块

func (*Factory) GetModule

func (p *Factory) GetModule(moduleType Type) *Module

GetModule 获取模块

func (*Factory) Register

func (p *Factory) Register(element *Module) error

Register 注册模块

type IHolder

type IHolder interface {
	GetModule(t Type) IModule
}

IHolder 持有者

type IModule

type IModule interface {
	Name() string
	Init(holder IHolder) error
	Start() error
	Stop() error
}

IModule 模块

type Module

type Module struct {
	Type            Type            // 模块类型
	Name            string          // 模块名称
	IModule         IModule         // 模块
	CreatorFunction CreatorFunction // 模块创建器
}

type Type

type Type uint32

Jump to

Keyboard shortcuts

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