cherry

package module
v1.3.12 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: MIT Imports: 14 Imported by: 15

README

欢迎使用cherry!

cherry logo cherry license go version cherry tag

  • 这是一款分布式的golang游戏服务器框架
  • 基于golang + nats.io + pomelo protocol技术构建
  • 它具备高性能、可伸缩、分布式、协程分组管理等特点。并且上手简单、易学
  • 让开发者更多的关注游戏业务,高效完成功能实现
  • 文档陆续补充中,欢迎加入一起建设框架

新增功能

  • 新增Actor model实现
  • 新增simple网络数据包结构(id(4bytes) + dataLen(4bytes) + data(n bytes))

讨论与交流

教程

多节点精简版聊天室(❤推荐)
  • 实现网页客户端,构建http server
  • 选择websocket作为连接器
  • 选择json做为通信格式
  • 实现创建房间
  • 实现发送消息
  • 实现广播消息
  • 示例代码跳转
多节点分布式游戏示例(❤强烈推荐)
  • 选择h5搭建一个客户端
  • 搭建web服节点
  • 搭建网关服节点
  • 搭建中心服节点
  • 搭建游戏服节点
  • 选择master做为发现服务节点
  • 实现部份基础功能(区服列表、多sdk帐号体系、帐号注册、帐号登录、创建角色、角色登录)
  • 示例代码跳转

核心功能

组件管理
  • 基于组件的方式组合功能,方便统一管理生命周期
  • 可根据需求自定义组件,并注册到框架,灵活扩展
  • 可配置cluster modestandalone mode
环境配置
  • 可配置多个环境的参数,方便切换
  • 所有系统参数、组件参数都基于profile文件配置,方便扩展
  • 可根据业务需求自由的拆分或组装多个profile子文件,精简配置,拒绝冗余
日志
  • 基于uber zap封装,性能良好
  • 可配置多文件进行日志输出
  • 基于rotatelogs处理切割日志
消息&路由
  • 实现pomelo网络数据包结构 & simple网络数据包结构
  • 包解码&编码
  • 消息路由
  • 消息序列化(自带json/protobuf)
  • 事件
连接器
  • tcp
  • websocket
  • http server
  • http client
  • kcp(未实现,以后作为组件集成)
集群&注册发现
  • 三种发现服务实现方式:
    • 开发用,直接读取本地的节点配置文件
    • 小规模用,基于nats.io创建一个master节点,实现单节点的发现服务
    • 线上用,基于etcd封装,实现集群方式的发现服务
  • 基于nats.io实现的RPC调用,默认提供同步/异步的调用方式
actor模型
  • 每个Actor独立运行在一个goroutine中,所有的逻辑都是串行处理
  • Actor接收三种消息:本地消息(Local)、远程消息(Remote)、事件消息(Event)
    • 三种消息都有自己的队列(Queue),每个队列依据FIFO原则进行消费
    • 本地消息(Local),用于接收游戏客户端发送过来的本地消息
    • 远程消息(Remote),用于Actor之间调用的远程消息
    • 事件消息(Event),通过订阅/发布进行的事件消息
  • Actor可以创建多个子Actor(ChildActor),子Actor的消息由父Actor进行路由转发
  • 通过cluster集群组件、discovery发现服务组件,进行跨节点的actor通信

扩展组件

cron组件
  • 基于github.com/robfig/cron/v3进行封装成组件
  • 性能良好
data-config组件
  • 策划配表读取管理组件
  • 可基于本地配置文件的方式加载
  • 可基于redis数据的方式加载
  • 可基于接口抽像自定义数据源加载
  • 支持自定义文件格式读取,目前已实现JSON格式读取
  • 支持缓存热更新
  • 可自定义类型检测
  • 可根据go-linq进行数据集合的条件查询
etcd组件
  • 基于etcd组件进行封装,节点集群和注册发现
gin组件
  • 集成gin组件,实现http server功能
  • 自定义controller,增加PreInit()Init()Stop()初始周期的管理
  • 增加几个常用的middleware组件
    • gin zap
    • recover with zap
    • cors跨域
    • max connect限流
  • 封装了GET/POST方式获取各种数据类型的函数
gorm组件
  • 集成gorm组件,实现mysql的数据库访问
  • 支持多个mysql数据库配置和管理
mongo组件
  • 集成mongo-driver驱动
  • 支持多个mongodb数据库配置和管理
待开放组件
  • db队列
  • gopher-lua脚本
  • 限流组件

游戏客户端SDK

游戏服务端架构示例(点击看大图)

game-server-architecture

致谢

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppBuilder added in v1.3.0

type AppBuilder struct {
	*Application
	// contains filtered or unexported fields
}

func Configure added in v1.1.5

func Configure(profileFilePath, nodeId string, isFrontend bool, mode NodeMode) *AppBuilder

func ConfigureNode added in v1.3.10

func ConfigureNode(node cfacade.INode, isFrontend bool, mode NodeMode) *AppBuilder

func (*AppBuilder) AddActors added in v1.3.0

func (p *AppBuilder) AddActors(actors ...cfacade.IActorHandler)

func (*AppBuilder) NetParser added in v1.3.0

func (p *AppBuilder) NetParser() cfacade.INetParser

func (*AppBuilder) Register added in v1.3.0

func (p *AppBuilder) Register(component ...cfacade.IComponent)

func (*AppBuilder) SetNetParser added in v1.3.0

func (p *AppBuilder) SetNetParser(parser cfacade.INetParser)

func (*AppBuilder) Startup added in v1.3.0

func (p *AppBuilder) Startup()

type Application

type Application struct {
	cfacade.INode
	// contains filtered or unexported fields
}

func NewApp

func NewApp(profileFilePath, nodeId string, isFrontend bool, mode NodeMode) *Application

NewApp create new application instance

func NewAppNode added in v1.3.10

func NewAppNode(node cfacade.INode, isFrontend bool, mode NodeMode) *Application

func (*Application) ActorSystem added in v1.3.0

func (a *Application) ActorSystem() cfacade.IActorSystem

func (*Application) All

func (a *Application) All() []cfacade.IComponent

func (*Application) Cluster added in v1.3.0

func (a *Application) Cluster() cfacade.ICluster

func (*Application) DieChan added in v1.1.22

func (a *Application) DieChan() chan bool

func (*Application) Discovery added in v1.3.0

func (a *Application) Discovery() cfacade.IDiscovery

func (*Application) Find

func (a *Application) Find(name string) cfacade.IComponent

func (*Application) IsFrontend added in v1.1.6

func (a *Application) IsFrontend() bool

func (*Application) NodeMode added in v1.1.6

func (a *Application) NodeMode() NodeMode

func (*Application) OnShutdown added in v1.1.0

func (a *Application) OnShutdown(fn ...func())

func (*Application) Register added in v1.1.5

func (a *Application) Register(components ...cfacade.IComponent)

func (*Application) Remove

func (a *Application) Remove(name string) cfacade.IComponent

Remove component by name

func (*Application) Running

func (a *Application) Running() bool

func (*Application) Serializer added in v1.3.0

func (a *Application) Serializer() cfacade.ISerializer

func (*Application) SetCluster added in v1.3.0

func (a *Application) SetCluster(cluster cfacade.ICluster)

func (*Application) SetDiscovery added in v1.3.0

func (a *Application) SetDiscovery(discovery cfacade.IDiscovery)

func (*Application) SetNetParser added in v1.3.1

func (a *Application) SetNetParser(netParser cfacade.INetParser)

func (*Application) SetSerializer added in v1.1.0

func (a *Application) SetSerializer(serializer cfacade.ISerializer)

func (*Application) Shutdown

func (a *Application) Shutdown()

func (*Application) StartTime added in v1.1.0

func (a *Application) StartTime() string

func (*Application) Startup

func (a *Application) Startup()

Startup load components before startup

type NodeMode added in v1.1.6

type NodeMode byte
const (
	Cluster    NodeMode = 1 // 集群模式
	Standalone NodeMode = 2 // 单机模式
)

Directories

Path Synopsis
components
cron Module
data-config Module
etcd Module
gin Module
gops Module
gorm Module
mongo Module
examples module
extend
base58
Package cherryBase58 file from https://github.com/akamensky/base58/blob/master/base58.go
Package cherryBase58 file from https://github.com/akamensky/base58/blob/master/base58.go
gob
map
Package cherryMap file from https://github.com/gogf/gf
Package cherryMap file from https://github.com/gogf/gf
mapstructure
Package cherryMapStructure exposes functionality to convert one arbitrary Go type into another, typically to convert a map[string]interface{} into a native Go structure.
Package cherryMapStructure exposes functionality to convert one arbitrary Go type into another, typically to convert a map[string]interface{} into a native Go structure.
net
queue
Package cherryQueue provides an efficient implementation of a multi-producer, single-consumer lock-free queue.
Package cherryQueue provides an efficient implementation of a multi-producer, single-consumer lock-free queue.
regex
Package cherryRegex file from https://github.com/gogf/gf
Package cherryRegex file from https://github.com/gogf/gf
slice
Package cherrySlice code from: https://github.com/beego/beego/blob/develop/core/utils/slice.go
Package cherrySlice code from: https://github.com/beego/beego/blob/develop/core/utils/slice.go
snowflake
Package cherrySnowflake code from: https://github.com/bwmarrin/snowflake snowflake provides a very simple Twitter snowflake generator and parser.
Package cherrySnowflake code from: https://github.com/bwmarrin/snowflake snowflake provides a very simple Twitter snowflake generator and parser.
sync
Package cherrySync cherrySync file from https://github.com/beego/beego/blob/develop/core/utils/safemap.go
Package cherrySync cherrySync file from https://github.com/beego/beego/blob/develop/core/utils/safemap.go
time
Package cherryTime code from: https://github.com/golang-module/carbon
Package cherryTime code from: https://github.com/golang-module/carbon
time_wheel
Package cherryTimeWheel file from https://github.com/RussellLuo/timingwheel
Package cherryTimeWheel file from https://github.com/RussellLuo/timingwheel
utils
Package cherryUtils file from https://github.com/gogf/gf
Package cherryUtils file from https://github.com/gogf/gf
rotatelogs
Package rotatelogs is a port of File-RotateLogs from Perl (https://metacpan.org/release/File-RotateLogs), and it allows you to automatically rotate output files when you write to them according to the filename pattern that you can specify.
Package rotatelogs is a port of File-RotateLogs from Perl (https://metacpan.org/release/File-RotateLogs), and it allows you to automatically rotate output files when you write to them according to the filename pattern that you can specify.
net

Jump to

Keyboard shortcuts

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