cherry

package module
v1.4.15 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2026 License: MIT Imports: 14 Imported by: 28

README

🍒 欢迎使用 cherry!

cherry logo cherry license go version cherry tag

  • 高性能分布式的 Golang 游戏服务器框架
  • 采用 Golang + Actor Model 构建,具备高性能、可伸缩等特性
  • 简单易学,让开发者更专注于游戏业务开发

📢 重要更新

  • 新增 Actor model 实现
  • 新增 simple 网络数据包结构(id(4bytes) + dataLen(4bytes) + data(n bytes))
  • 示例代码迁移examples
  • 组件库迁移components
  • 文档地址点击查看

💬 讨论与交流

📖 示例

单节点精简版聊天室

适合新手熟悉项目,具备以下特性:

  • 基于网页客户端,构建 HTTP 服务器
  • 采用 WebSocket 作为连接器
  • 使用 JSON 作为通信格式
  • 实现创建房间、发送消息、广播消息等功能

准备步骤:

多节点分布式游戏示例

适合作为基础框架构建游戏服务端,特性如下:

  • 基于 H5 构建客户端
  • 搭建 Web 服、网关服、中心服、游戏服等节点
  • 实现区服列表、多 SDK 帐号体系、帐号注册、登录、创建角色等功能

准备步骤:

🌟 核心功能

组件管理
  • 以组件方式组合功能,便于统一管理生命周期
  • 支持自定义组件注册,灵活扩展
  • 可配置集群模式和单机模式
环境配置
  • 支持多环境参数配置切换
  • 基于 profile 文件配置系统和组件参数
  • 可自由拆分或组装 profile 子文件,精简配置
Actor 模型
  • 个 Actor 独立运行于一个 goroutine,逻辑串行处理
  • 接收本地、远程、事件三种消息,各自有独立队列按 FIFO 原则消费
  • 可创建子 Actor,消息由父 Actor 路由转发
  • 支持跨节点 Actor 通信
集群 & 注册发现
  • 提供三种发现服务实现方式
  • 基于 nats.io 实现 RPC 调用,提供同步 / 异步方式
连接器
  • 支持 tcp、websocket、http server、http client 等
  • kcp 组件计划后续集成
消息 & 路由
  • 实现多种网络数据包结构及编解码
  • 支持消息路由、序列化(json/protobuf)、事件处理
日志
  • 基于 uber zap 封装,性能优良
  • 支持多文件输出、日志切割等功能

🧰 扩展组件

已开放组件
  • data-config 组件 :策划配表读取管理,支持多种加载方式及数据查询
  • etcd 组件 :基于 etcd 封装,用于节点集群和注册发现
  • gin 组件 :集成 gin 实现 http server 功能,增加管理周期和中间件组件
  • gorm 组件 :集成 gorm 实现 mysql 数据库访问,支持多数据库配置
  • mongo 组件 :集成 mongo-driver,支持多 mongodb 数据库配置
  • cron 组件 :基于 robfig/cron 封装,性能良好
待开放组件
  • 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