cherry

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2022 License: MIT Imports: 26 Imported by: 0

README

欢迎使用cherry!

cherry logo cherry license go version cherry tag

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

讨论与交流

  • QQ群:191651647
  • 扫码加群

qr-code

教程

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

核心功能

组件管理
  • 基于组件的方式组合功能,方便统一管理生命周期
  • 可根据需求自定义组件,并注册到框架,灵活扩展
  • 可配置cluster modestandalone mode
环境配置
  • 可配置多个环境的参数,方便切换
  • 所有系统参数、组件参数都基于profile文件配置,方便扩展
  • 可根据业务需求自由的拆分或组装多个profile子文件,精简配置,拒绝冗余
日志
  • 基于uber zap封装,性能良好
  • 可配置多文件进行日志输出
  • 基于rotatelogs处理切割日志
消息&路由
  • 实现包结构pomelo protocol
  • 包解码&编码
  • 消息路由
  • 消息序列化(自带json/protobuf)
  • 事件
连接器
  • tcp
  • websocket
  • http server
  • http client
  • kcp(未实现,以后作为组件集成)
集群&注册发现
  • 三种发现服务实现方式:
    • 开发用,直接读取本地的节点配置文件
    • 小规模用,基于nats.io创建一个master节点,实现单节点的发现服务
    • 线上用,基于etcd封装,实现集群方式的发现服务
  • 基于nats.io实现的RPC调用,默认提供同步/异步的调用方式

扩展组件

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

func AddNodeRouter

func AddNodeRouter(nodeType string, routingFunc crouter.RoutingFunc)

func Configure

func Configure(profilePath, profileName, nodeId string) cfacade.IApplication

func GetConnectors

func GetConnectors() []cfacade.IConnector

func GetRPC

func GetRPC() cfacade.RPCClient

func Kick

func Kick(nodeId string, uid cfacade.UID, val interface{}, close bool) error

func PostEvent

func PostEvent(event cfacade.IEvent)

func PublishRemote

func PublishRemote(nodeId string, route string, arg interface{})

func PublishRemoteByRoute

func PublishRemoteByRoute(route string, arg interface{})

func Push

func Push(frontendId string, route string, uid cfacade.UID, val interface{}) error

func RegisterCommand

func RegisterCommand(command ccommand.ICommand)

func RegisterComponent

func RegisterComponent(component ...cfacade.IComponent)

func RegisterConnector

func RegisterConnector(connector cfacade.IConnector)

func RegisterHandler

func RegisterHandler(handler ...cfacade.IHandler)

func RegisterHandlerGroup

func RegisterHandlerGroup(group ...*chandler.HandlerGroup)

func RequestRemote

func RequestRemote(nodeId string, route string, arg, reply interface{}, timeout ...time.Duration) int32

func RequestRemoteByRoute

func RequestRemoteByRoute(route string, arg, reply interface{}, timeout ...time.Duration) int32

func Run

func Run(isFrontend bool, nodeMode NodeMode)

func SetDataCompression

func SetDataCompression(compression bool)

func SetDictionary

func SetDictionary(dict map[string]uint16)

func SetHandlerOptions

func SetHandlerOptions(opts ...chandler.Option)

func SetHandshake

func SetHandshake(key string, value interface{})

func SetHeartbeat

func SetHeartbeat(t time.Duration)

func SetOnShutdown

func SetOnShutdown(fn ...func())

func SetPacketCodec

func SetPacketCodec(codec cfacade.IPacketCodec)

func SetSerializer

func SetSerializer(serializer cfacade.ISerializer)

Types

type Application

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

func App

func App() *Application

func NewApp

func NewApp(profilePath, profileName, nodeId string) *Application

NewApp create new application instance

func (*Application) All

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

func (*Application) DieChan

func (a *Application) DieChan() chan bool

func (*Application) Find

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

func (*Application) IsFrontend

func (a *Application) IsFrontend() bool

func (*Application) NodeMode

func (a *Application) NodeMode() NodeMode

func (*Application) OnShutdown

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

func (*Application) Register

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

func (*Application) Remove

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

Remove remove component by name

func (*Application) Running

func (a *Application) Running() bool

func (*Application) SetPacketCodec

func (a *Application) SetPacketCodec(codec cfacade.IPacketCodec)

func (*Application) SetSerializer

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

func (*Application) Shutdown

func (a *Application) Shutdown()

func (*Application) StartTime

func (a *Application) StartTime() string

func (*Application) Startup

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

Startup load components before startup

type NodeMode

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

Directories

Path Synopsis
components
gin 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
map
Package cherryMap file from https://github.com/beego/beego/blob/develop/core/utils/safemap.go
Package cherryMap file from https://github.com/beego/beego/blob/develop/core/utils/safemap.go
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
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
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