tgf - 一个开箱即用的golang游戏服务器框架

tgf框架

tgf框架是使用golang开发的一套游戏分布式框架.属于开箱即用的项目框架,目前适用于中小型团队,独立开发者,快速开发使用.框架提供了一整套开发工具,并且定义了模块开发规范.开发者只需要关注业务逻辑即可,无需关心用户并发和节点状态等复杂情况.

使用介绍

创建业务逻辑节点

package quick_start

import (
	"context"
	"github.com/thkhxm/tgf"
	"github.com/thkhxm/tgf/log"
	"github.com/thkhxm/tgf/rpc"
	"github.com/thkhxm/tgf_example/common/pb"
)

//***************************************************
//@Link  https://github.com/thkhxm/tgf
//@Link  https://gitee.com/timgame/tgf
//@QQ群 7400585
//author tim.huang<thkhxm@gmail.com>
//@Description
//2023/11/21
//***************************************************

//服务启动函数,在这个例子中我们将网关和业务节点放在了同一个服务中启动.
func Startup() {
   
	c := rpc.NewRPCServer(). //创建一个rpc服务
					WithGatewayWS("8032", "/example",nil). //启动一个网关
					WithService(&HallService{
   }).       //启动一个service的服务
					WithWhiteService("SayHello"). //添加客户端请求接口到白名单,无需登录即可访问
					WithCache(tgf.CacheModuleClose).   //关闭redis等缓存服务
					Run()
	select {
   
	case <-c:
		log.InfoTag("service", "service is down ")

	}
}
//接口约束
var _ rpc.IService = &HallService{
   }

// HallService
// @Description: implements rpc.IService
type HallService struct {
   
	rpc.Module
}
//客户端请求接口
func (h *HallService) SayHello(ctx context.Context, args *rpc.Args[*pb.DefaultRequest], reply *rpc.Reply[*pb.DefaultRequest]) (err error) {
   
	log.InfoTag("hall", "%s say hello ", args.GetData().Val)
	reply.SetData(&pb.DefaultRequest{
   Val: "good luck"})
	return
}

//服务器rpc请求接口
func (h *HallService) GetMyNodeId(ctx context.Context, args *rpc.DefaultArgs, reply *rpc.DefaultReply) (err error) {
   
	log.InfoTag("rpc", "hello %s", args.C)
	reply.C = tgf.NodeId
	return
}

//模块名称
func (h *HallService) GetName() string {
   
	return "hall"
}
//模块版本
func (h *HallService) GetVersion() string {
   
	return "v1.0"
}
//启动函数,该函数会在服务启动之后立马执行
func (h *HallService) Startup() (bool, error) {
   
	return true, nil
}

可以看到我们创建一个服务十分简单,只需要实现IService接口即可.这时候服务就完全启动了.而开发人员只需要关注业务代码即可.

其他详细的教程,可以查看

项目文档

项目地址

规划

项目后续会更新系列教程文章和视频教程,并且开源项目案例.也会不断的更新和优化项目框架.欢迎大家加入qq群一起交流和探讨.

交流群

QQ群:7400585

技术选型

Golang开发版本: 1.21.1

技术 说明 仓库地址
rpcx 底层rpc的实现 https://github.com/smallnest/rpcx
redis 提供数据缓存 https://redis.io/
hashmap 线程安全的集合 https://github.com/cornelk/hashmap
ants 高性能go协程池 https://github.com/panjf2000/ants
redislock 分布式redis锁 https://github.com/bsm/redislock
snowflake 雪花算法 https://github.com/bwmarrin/snowflake
doublejump 一致性hash https://github.com/edwingeng/doublejump
godotenv 环境变量工具 https://github.com/joho/godotenv
zap 日志框架 https://go.uber.org/zap
lumberjack 日志切割工具 https://gopkg.in/natefinch/lumberjack.v2
excelize Excel工具 https://github.com/qax-os/excelize
sonic json高性能工具 https://github.com/bytedance/sonic/

基础架构图

相关推荐

  1. golang游戏服务器 - tgf系列课程02

    2023-12-07 16:32:02       59 阅读
  2. golang游戏服务器 - tgf系列课程01

    2023-12-07 16:32:02       62 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-07 16:32:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-07 16:32:02       101 阅读
  3. 在Django里面运行非项目文件

    2023-12-07 16:32:02       82 阅读
  4. Python语言-面向对象

    2023-12-07 16:32:02       91 阅读

热门阅读

  1. uniapp连接蓝牙称(接收,发送)

    2023-12-07 16:32:02       51 阅读
  2. 面试篇算法:(一:排序算法)

    2023-12-07 16:32:02       60 阅读
  3. cesium 融合视频

    2023-12-07 16:32:02       63 阅读
  4. 【开源存储】OpenZFS文件系统部署实践

    2023-12-07 16:32:02       63 阅读
  5. 8. 队列

    8. 队列

    2023-12-07 16:32:02      60 阅读
  6. vue3学习网站

    2023-12-07 16:32:02       63 阅读
  7. Elasticsearch-Kibana使用教程

    2023-12-07 16:32:02       40 阅读
  8. Android Audio实战——音频焦点监听(十)

    2023-12-07 16:32:02       60 阅读
  9. mysql基本命令

    2023-12-07 16:32:02       52 阅读
  10. vue3 element-plus 将路由和激活菜单绑定

    2023-12-07 16:32:02       57 阅读
  11. 传导电流密度方向与磁矢位方向相同

    2023-12-07 16:32:02       48 阅读