tgf

package module
v1.0.18 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2024 License: Apache-2.0 Imports: 8 Imported by: 7

README

Go Report Card

关于 tgf

tgf框架是使用golang开发的一套游戏分布式框架.

属于开箱即用的项目框架,目前适用于中小型团队,独立开发者,快速开发使用.

框架提供了一整套开发工具,并且定义了模块开发规范.

开发者只需要关注业务逻辑即可,无需关心用户并发和节点状态等复杂情况.

API 项目地址
项目文档
国内项目文档
项目案例地址 知乎博客
CSDN专栏
B站教程

交流群

QQ群:7400585

技术选型

Golang开发版本:  1.22
技术 说明 仓库地址
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/

规划

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

Documentation

Overview

Package tgf @Description: 框架基础包

Index

Constants

View Source
const (
	// RuntimeModuleDev 开发环境
	RuntimeModuleDev = "dev"

	// RuntimeModuleTest 测试环境
	RuntimeModuleTest = "test"

	// RuntimeModuleRelease 生产环境
	RuntimeModuleRelease = "release"
)

运行环境

View Source
const (
	ContextKeyUserId           = "UserId"
	ContextKeyRPCType          = "RPCType"
	ContextKeyTemplateUserId   = "TemplateUserId"
	ContextKeyNodeId           = "NodeId"
	ContextKeyCloseLocalCache  = "CloseLocalCache"
	ContextKeyBroadcastUserIds = "BroadcastUserIds"
	ContextKeyTRACEID          = "TraceId"
	ContextKeyHash             = "__hash"
)
View Source
const (
	RPCTip          = "rpc_tip"
	RPCBroadcastTip = "rpc_broadcast_tip"
)
View Source
const AdminServiceModuleName = "admin"
View Source
const GatewayServiceModuleName = "gate"
View Source
View Source
const MonitorServiceModuleName = "monitor"
View Source
const (
	RedisKeyUserNodeMeta = "user:node:meta:%v"
)

redisKey

Variables

View Source
var (
	ErrorRPCTimeOut = errors.New("rpc time out")
	LocalEmpty      = errors.New("local cache empty")
	RedisEmpty      = errors.New("redis cache empty")
	DBEmpty         = errors.New("db cache empty")
)
View Source
var NodeId = ""
View Source
var ServerModule = false

Functions

func AddDestroyHandler

func AddDestroyHandler(handler IDestroyHandler)

func GetStrConfig

func GetStrConfig[T int | int32 | string | int64 | float32 | float64](env Environment) (res T)

func GetStrListConfig

func GetStrListConfig(env Environment) (res []string)

func InitConfig

func InitConfig()

Types

type CacheModule

type CacheModule int
const (
	CacheModuleRedis CacheModule = iota
	CacheModuleClose
)

type Environment

type Environment string
const (
	// EnvironmentLoggerPath 日志输出路径
	EnvironmentLoggerPath Environment = "LogPath"

	// EnvironmentLoggerLevel 日志最低输出级别
	EnvironmentLoggerLevel       Environment = "LogLevel"
	EnvironmentLoggerIgnoredTags Environment = "LogIgnoredTags"

	// EnvironmentRuntimeModule 运行环境,有以下可选运行环境
	// dev test release
	// RuntimeModuleDev RuntimeModuleTest RuntimeModuleRelease
	EnvironmentRuntimeModule Environment = "RuntimeModule"

	// EnvironmentConsulAddress consul地址
	EnvironmentConsulAddress Environment = "ConsulAddress"

	// EnvironmentConsulPath consul路径
	//
	// 默认使用/tgf,如需区分不同环境可以使用自定义的不同的路径 例如 /test 或者 /dev /tim
	EnvironmentConsulPath Environment = "ConsulPath"

	// EnvironmentRedisAddr redis地址 127.0.0.1::6379
	EnvironmentRedisAddr Environment = "RedisAddr"

	// EnvironmentRedisPassword redis密码
	EnvironmentRedisPassword Environment = "RedisPassword"

	// EnvironmentRedisDB redis的db
	EnvironmentRedisDB Environment = "RedisDB"
	// EnvironmentRedisCluster redis cluster 开关 0 关闭 1 开启,默认关闭
	EnvironmentRedisCluster Environment = "RedisCluster"

	// EnvironmentMySqlUser mysql用户名
	EnvironmentMySqlUser Environment = "MySqlUser"

	// EnvironmentMySqlPwd mysql密码
	EnvironmentMySqlPwd Environment = "MySqlPwd"

	// EnvironmentMySqlAddr mysql地址
	EnvironmentMySqlAddr Environment = "MySqlAddr"

	// EnvironmentMySqlPort mysql端口
	EnvironmentMySqlPort Environment = "MySqlPort"

	// EnvironmentMySqlDB mysql库
	EnvironmentMySqlDB Environment = "MySqlDB"

	// EnvironmentServicePort 当前进程提供的服务端口
	EnvironmentServicePort    = "ServicePort"
	EnvironmentServiceAddress = "ServiceAddress"

	EnvironmentGatePush = "GatePush"
)

环境变量

type GameError added in v1.0.7

type GameError interface {
	Error() string
	Code() int32
}

type IDestroyHandler

type IDestroyHandler interface {
	Destroy()
}

Directories

Path Synopsis
Package db @Description: 数据缓存相关 @Link https://github.com/bsm/redislock redis分布式锁
Package db @Description: 数据缓存相关 @Link https://github.com/bsm/redislock redis分布式锁
exp
Package log @Description: log包,日志相关业务 @Link https://github.com/natefinch/lumberjack @Link https://github.com/uber-go/zap
Package log @Description: log包,日志相关业务 @Link https://github.com/natefinch/lumberjack @Link https://github.com/uber-go/zap
rpc
Package rpc @Description: rpc的封装,使用了rpcx框架 @Link: https://doc.rpcx.io/part4/alias.html rpcx框架 @Ref:
Package rpc @Description: rpc的封装,使用了rpcx框架 @Link: https://doc.rpcx.io/part4/alias.html rpcx框架 @Ref:
Package util @Description: 工具包 @Link: https://github.com/panjf2000/ants 是一个高性能且低损耗的 goroutine 池 @Ref:
Package util @Description: 工具包 @Link: https://github.com/panjf2000/ants 是一个高性能且低损耗的 goroutine 池 @Ref:

Jump to

Keyboard shortcuts

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