plugin

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientPlugin

type ClientPlugin interface {
	Plugin
	// ModifyClientOptions 允许插件修改客户端选项
	ModifyClientOptions([]grpc.DialOption) []grpc.DialOption
}

ClientPlugin 定义了客户端插件的接口

type InterceptorPlugin

type InterceptorPlugin interface {
	Plugin
	// UnaryServerInterceptor 返回一个一元服务端拦截器
	UnaryServerInterceptor() grpc.UnaryServerInterceptor
	// StreamServerInterceptor 返回一个流服务端拦截器
	StreamServerInterceptor() grpc.StreamServerInterceptor
	// UnaryClientInterceptor 返回一个一元客户端拦截器
	UnaryClientInterceptor() grpc.UnaryClientInterceptor
	// StreamClientInterceptor 返回一个流客户端拦截器
	StreamClientInterceptor() grpc.StreamClientInterceptor
}

InterceptorPlugin 定义了拦截器插件的接口

type LifecycleHook

type LifecycleHook interface {
	// BeforeStart 在服务启动前调用
	BeforeStart(context.Context) error
	// AfterStart 在服务启动后调用
	AfterStart(context.Context) error
	// BeforeStop 在服务停止前调用
	BeforeStop(context.Context) error
	// AfterStop 在服务停止后调用
	AfterStop(context.Context) error
}

LifecycleHook 定义了插件生命周期钩子

type LifecycleManager

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

LifecycleManager 管理插件的生命周期事件

func NewLifecycleManager

func NewLifecycleManager(manager *Manager) *LifecycleManager

NewLifecycleManager 创建一个新的生命周期管理器

func (*LifecycleManager) ExecuteAfterStart

func (lm *LifecycleManager) ExecuteAfterStart(ctx context.Context) error

ExecuteAfterStart 执行所有插件的AfterStart钩子

func (*LifecycleManager) ExecuteAfterStop

func (lm *LifecycleManager) ExecuteAfterStop(ctx context.Context) error

ExecuteAfterStop 执行所有插件的AfterStop钩子

func (*LifecycleManager) ExecuteBeforeStart

func (lm *LifecycleManager) ExecuteBeforeStart(ctx context.Context) error

ExecuteBeforeStart 执行所有插件的BeforeStart钩子

func (*LifecycleManager) ExecuteBeforeStop

func (lm *LifecycleManager) ExecuteBeforeStop(ctx context.Context) error

ExecuteBeforeStop 执行所有插件的BeforeStop钩子

type Manager

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

Manager 管理所有已注册的插件

func NewManager

func NewManager() *Manager

NewManager 创建一个新的插件管理器

func (*Manager) ApplyClientPlugins

func (m *Manager) ApplyClientPlugins(opts []grpc.DialOption) []grpc.DialOption

ApplyClientPlugins 将所有客户端插件应用到gRPC客户端选项

func (*Manager) ApplyServerPlugins

func (m *Manager) ApplyServerPlugins(server *grpc.Server) error

ApplyServerPlugins 将所有服务端插件应用到gRPC服务器

func (*Manager) Close

func (m *Manager) Close() error

Close 关闭所有已注册的插件

func (*Manager) Get

func (m *Manager) Get(name string) (Plugin, bool)

Get 获取一个已注册的插件

func (*Manager) GetAll

func (m *Manager) GetAll() []Plugin

GetAll 获取所有已注册的插件

func (*Manager) GetByType

func (m *Manager) GetByType(pluginType interface{}) []Plugin

GetByType 获取特定类型的所有插件

func (*Manager) GetInterceptors

func (m *Manager) GetInterceptors() (
	unaryServer []grpc.UnaryServerInterceptor,
	streamServer []grpc.StreamServerInterceptor,
	unaryClient []grpc.UnaryClientInterceptor,
	streamClient []grpc.StreamClientInterceptor,
)

GetInterceptors 获取所有拦截器插件的拦截器

func (*Manager) Init

func (m *Manager) Init() error

Init 初始化所有已注册的插件

func (*Manager) Register

func (m *Manager) Register(p Plugin) error

Register 注册一个插件

type Plugin

type Plugin interface {
	// Name 返回插件的名称
	Name() string
	// Init 初始化插件,在服务启动前调用
	Init() error
	// Close 关闭插件,在服务关闭时调用
	Close() error
}

Plugin 定义了插件的基本接口

type ServerPlugin

type ServerPlugin interface {
	Plugin
	// RegisterWithServer 将插件注册到gRPC服务器
	RegisterWithServer(*grpc.Server) error
}

ServerPlugin 定义了服务端插件的接口

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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