cherryFacade

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2021 License: MIT Imports: 3 Imported by: 25

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 EventFn

type EventFn func(e IEvent)

EventFn 事件注册函数

type FrontendId

type FrontendId = string // 前端节点id

type HandlerFn

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

HandlerFn 函数反射信息

type IAppContext

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

IAppContext App上下文

type IApplication

type IApplication interface {
	INode
	ISerializer
	IPacketCodec
	Running() 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 IEvent

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

IEvent 事件接口

type IExecutor

type IExecutor interface {
	Invoke()
	String() string
}

type IHandler

type IHandler interface {
	IAppContext                                       // 应用实例上线文
	Name() string                                     // handler名称(用于消息路由)
	SetName(name string)                              // 设置handler名称
	OnPreInit()                                       // 预初始化方法(对象实例化前)
	OnInit()                                          // 初始方法(PreInit之后)
	OnAfterInit()                                     // 最后的初始化方法(Init之后)
	OnStop()                                          // 停止handler运行
	Events() map[string][]EventFn                     // 已注册的事件列表
	Event(name string) ([]EventFn, 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 INetConn

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

type INetwork

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

INetwork 网络处理接口

type INode

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

INode 结点信息

type INodeDiscovery

type INodeDiscovery interface {
	All() NodeMap
	GetType(nodeId string) (nodeType string, err error)
	Get(nodeId string) INode
	Sync()
	AddListener(listener INodeListener)
}

type INodeListener

type INodeListener interface {
	Add(node INode)
	Remove(node 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 NodeMap

type NodeMap map[string]map[string]INode

NodeMap {key:nodeType,value:{key:nodeId,value:INode}}

type OnConnectListener

type OnConnectListener func(conn INetConn)

OnConnectListener 建立连接时监听的函数

type SID

type SID = int64 // session唯一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