gogame

package module
v0.0.0-...-ebdab26 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2022 License: Apache-2.0 Imports: 21 Imported by: 0

README

TODO

  • 网关
  • 分布式锁
  • 分布式定时任务
  • 注册中心
  • 分布式事物
  • 负载均衡
  • 限流器

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(opts *Options, modules ...Module)

Run 模块注册入口,必须提供Options与Module

Types

type Agent

type Agent interface {
	WriteMsg(msg interface{})
	LocalAddr() net.Addr
	RemoteAddr() net.Addr
	Close()
	UserData() interface{}
	SetUserData(data interface{})
}

type AgentHook

type AgentHook interface {
	OnConnect(Agent)
	OnClose(Agent)
}

type Gate

type Gate struct {
	MsgMaxLen    uint32          // 最大消息长度
	MsgMinLen    uint32          // 最小消息长度
	MaxConnNum   int             // 最大连接数
	WriteBuffer  int             // 发送消息时的写缓冲区大小
	Processor    route.Processor // 消息处理
	AgentHandler AgentHook       // agent handler

	// websocket
	WSAddr      string
	CertFile    string
	KeyFile     string
	RootCAFile  string
	HTTPTimeout time.Duration

	// tcp
	TCPAddr      string
	MsgHeaderLen int
	LittleEndian bool
	// contains filtered or unexported fields
}

Gate 基础模块:网关,用于端口监听以及消息转发,一般需要自己实现一个包含本Gate的组合Gate或者直接套用

func (*Gate) Close

func (gate *Gate) Close()

func (*Gate) Start

func (gate *Gate) Start()

type Module

type Module interface {
	// Init 初始化工作
	// 每个模块初始化工作需要做的内容至少包括:
	// 1. 注册自己需要被其他模块直接调用的RPC函数
	// 2. 给自己模块的消息注册路由
	Init()

	// Run 运行模块
	// 每个模块必须自己Run Skeleton
	Run()

	// Running 模块是否已经运行起来了
	Running() bool

	// Destroy 处理模块销毁工作
	// 每个模块必须自己Destroy Skeleton
	Destroy()
}

type Options

type Options struct {
	ServeId uint16 // 服务器ID

	// cluster option
	ClusterAddr      string
	ClusterConnAddrs []string

	// pprof port
	ProfileAddr string
}

Options 服务器选项

type Skeleton

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

Skeleton 模块骨架,用于每个模块消息、任务、模块间的调度 每个模块需要包含骨架

func NewSkeleton

func NewSkeleton() *Skeleton

func (*Skeleton) AfterFunc

func (s *Skeleton) AfterFunc(d time.Duration, cb func()) (timer.TaskID, error)

func (*Skeleton) AsynCall

func (s *Skeleton) AsynCall(server *chanrpc.Server, id interface{}, args ...interface{})

func (*Skeleton) ChanRPCServer

func (s *Skeleton) ChanRPCServer() *chanrpc.Server

func (*Skeleton) Close

func (s *Skeleton) Close()

func (*Skeleton) CronFunc

func (s *Skeleton) CronFunc(desc string, cb func()) (timer.TaskID, error)

func (*Skeleton) Go

func (s *Skeleton) Go(f func(), cb func())

func (*Skeleton) RegisterChanRPC

func (s *Skeleton) RegisterChanRPC(id interface{}, f interface{})

func (*Skeleton) Run

func (s *Skeleton) Run()

Jump to

Keyboard shortcuts

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