cherryFacade

package
v1.1.24 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2022 License: MIT Imports: 5 Imported by: 59

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppContext

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

AppContext 继承自IApplication实现默认的方法

func (*AppContext) App

func (b *AppContext) App() IApplication

func (*AppContext) Set

func (b *AppContext) Set(app IApplication)

type Component

type Component struct {
	AppContext
}

Component base component

func (*Component) Init

func (*Component) Init()

func (*Component) Name

func (*Component) Name() string

func (*Component) OnAfterInit

func (*Component) OnAfterInit()

func (*Component) OnBeforeStop

func (*Component) OnBeforeStop()

func (*Component) OnStop

func (*Component) OnStop()

type EventFunc added in v1.1.6

type EventFunc func(e IEvent)

EventFunc 事件注册函数

type FrontendId

type FrontendId = string // 前端节点id

type HandlerFn

type HandlerFn struct {
	Type    reflect.Type
	Value   reflect.Value
	InArgs  []reflect.Type
	OutArgs []reflect.Type
	IsRaw   bool
}

HandlerFn 函数反射信息

type IAppContext

type IAppContext interface {
	Set(app IApplication)
	App() IApplication
}

IAppContext App上下文

type IApplication

type IApplication interface {
	INode
	ISerializer
	IPacketCodec
	Running() bool                    // 是否运行中
	DieChan() chan bool               // die chan
	IsFrontend() bool                 // 是否为前端节点
	Find(name string) IComponent      // 根据name获取组件对象
	Remove(name string) IComponent    // 根据name移除组件对象
	All() []IComponent                // 获取所有组件列表
	OnShutdown(fn ...func())          // 关闭前执行的函数
	Startup(components ...IComponent) // 启动应用实例
	Shutdown()                        // 关闭应用实例
}

type IComponent

type IComponent interface {
	IAppContext
	Name() string
	Init()
	OnAfterInit()
	OnBeforeStop()
	OnStop()
}

type IConnector

type IConnector interface {
	OnStart()
	OnStop()
	OnConnect(listener ...OnConnectListener) // 启动前设置连接器监听函数
}

IConnector 网络连接器接口

type IDiscovery added in v1.1.5

type IDiscovery interface {
	Name() string                                                 // 发现服务名称
	Init(app IApplication)                                        // 初始化函数
	List() []IMember                                              // 获取成员列表
	ListByType(nodeType string, filterNodeId ...string) []IMember // 根据节点类型获取列表
	GetType(nodeId string) (nodeType string, err error)           // 根据节点id获取类型
	GetMember(nodeId string) (member IMember, found bool)         // 获取成员
	AddMember(member IMember)                                     // 添加成员
	RemoveMember(nodeId string)                                   // 移除成员
	OnAddMember(listener MemberListener)                          // 添加成员监听函数
	OnRemoveMember(listener MemberListener)                       // 移除成员监听函数
	OnStop()                                                      // 停止当前发现服务
}

IDiscovery 节点发现接口

type IEvent

type IEvent interface {
	Name() string    // 事件名称
	UniqueId() int64 // 事件唯一id
}

IEvent 事件接口

type IHandler

type IHandler interface {
	IAppContext                                       // 应用实例上线文
	Name() string                                     // handler名称(用于消息路由)
	SetName(name string)                              // 设置handler名称
	OnPreInit()                                       // 预初始化方法(对象实例化前)
	OnInit()                                          // 初始方法(PreInit之后)
	OnAfterInit()                                     // 最后的初始化方法(Init之后)
	OnStop()                                          // 停止handler运行
	Events() map[string][]EventFunc                   // 已注册的事件列表
	Event(name string) ([]EventFunc, bool)            // 根据事件名获取事件列表
	LocalHandlers() map[string]*HandlerFn             // 已注册的本地handler列表(网络消息的逻辑处理函数)
	LocalHandler(funcName string) (*HandlerFn, bool)  // 根据handler名称获取本地handler
	RemoteHandlers() map[string]*HandlerFn            // 已注册的远程handler列表(内部rpc调用的逻辑处理函数)
	RemoteHandler(funcName string) (*HandlerFn, bool) // 根据handler名称获取远程handler
}

IHandler 消息处理句柄接口,用于包装消息处理逻辑

type IMember added in v1.1.5

type IMember interface {
	GetNodeId() string
	GetNodeType() string
	GetAddress() string
	GetSettings() map[string]string
}

type INetConn

type INetConn interface {
	net.Conn
	GetNextMessage() (b []byte, err error)
}

type INetwork

type INetwork interface {
	Push(route string, val interface{})                           // 推送消息对客户端
	Kick(reason interface{})                                      // 踢下线
	Response(mid uint, val interface{}, isError ...bool)          // 回复消息到客户端
	RPC(route string, val interface{}, rsp *cherryProto.Response) // 调用rpc
	SendRaw(bytes []byte)                                         // write raw data to client
	RemoteAddr() string                                           // 连接者的地址信息
	Close()                                                       // 关闭接口
}

INetwork 网络处理接口

type INode

type INode interface {
	NodeId() string         // 节点id(全局唯一)
	NodeType() string       // 节点类型
	Address() string        // 对外网络监听地址
	RpcAddress() string     // rpc监听地址
	Settings() jsoniter.Any // 节点配置参数
	Enabled() bool          // 是否启用
}

INode 节点信息

type IPacket

type IPacket interface {
	Type() byte
	Len() int
	Data() []byte
	SetData([]byte)
}

type IPacketCodec

type IPacketCodec interface {
	PacketDecode(data []byte) ([]IPacket, error)
	PacketEncode(typ byte, data []byte) ([]byte, error)
}

type ISerializer

type ISerializer interface {
	Marshal(interface{}) ([]byte, error) // 编码
	Unmarshal([]byte, interface{}) error // 解码
	Name() string                        // 序列化类型的名称
}

ISerializer 消息序列化

type MemberListener added in v1.1.5

type MemberListener func(member IMember) // MemberListener 成员增、删监听函数

type OnConnectListener

type OnConnectListener func(conn INetConn)

OnConnectListener 建立连接时监听的函数

type RPCClient added in v1.1.17

type RPCClient interface {
	CallLocal(nodeId string, packet *cherryProto.LocalPacket) error
	CallRemote(nodeId string, route string, val interface{}, timeout time.Duration, rsp *cherryProto.Response)
	CallRemoteAsync(nodeId string, route string, val interface{})
	SendKick(nodeId string, uid UID, reason interface{})
	SendPush(nodeId string, route string, uid UID, val interface{})
	// contains filtered or unexported methods
}

type RPCServer added in v1.1.17

type RPCServer interface {
	// contains filtered or unexported methods
}

type SID

type SID = string // session unique id

type UID

type UID = int64 // 用户唯一id user unique id

Jump to

Keyboard shortcuts

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