component

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Base

type Base struct{}

Base 空组件,实现组件时,优先嵌入此基类,然后根据基类方法进行重写 可方便实现Component,无需每个Component都要实现两个方法

func (*Base) OnInit

func (*Base) OnInit()

func (*Base) OnShutdown

func (*Base) OnShutdown()

type CompWithOptions

type CompWithOptions struct {
	Comp Component
	Opts []Option
}

type Component

type Component interface {
	// OnInit 初始化组件时调用.
	OnInit()
	// OnShutdown 停止组件时调用.
	OnShutdown()
}

Component 组件接口

type Components

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

func (*Components) List

func (cs *Components) List() []CompWithOptions

List 获取所有已注册组件

func (*Components) Register

func (cs *Components) Register(c Component, options ...Option)

Register 全局注册组件,必须在服务启动之前初始化

type Handler

type Handler struct {
	Receiver reflect.Value  // 方法接收者
	Method   reflect.Method // 方法存根
	Type     reflect.Type   // 方法参数类型
	IsRawArg bool           // 数据是否需要被序列化,true代表不需要
}

Handler 消息处理器,当前仅支持单个自定义参数

type Option

type Option func(options *options)

func WithMethodNameFunc

func WithMethodNameFunc(fn func(string) string) Option

WithMethodNameFunc 覆盖默认生成的方法名 当前仅支持一些基本策略,如: strings.ToUpper/strings.ToLower 或自行根据方法名判断后进行重写

func WithServiceName

func WithServiceName(name string) Option

WithServiceName 覆盖默认生成的服务名称

type Service

type Service struct {
	Name     string              // 服务名称
	Type     reflect.Type        // 接收者类型
	Receiver reflect.Value       // 该服务下所有方法的接收者
	Handlers map[string]*Handler // 该服务下属的所有方法
	Options  options             // options
}

Service 服务,绑定消息处理器用以处理发生的消息

func NewService

func NewService(comp Component, opts []Option) *Service

func (*Service) ExtractHandler

func (s *Service) ExtractHandler() error

ExtractHandler 反射提取满足以下条件的方法 - 两个显示入参 - 第一个是 *net.request - 另一个是 []byte 或者 任意指针类型 pointer

Jump to

Keyboard shortcuts

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