fatchoy

package module
v1.3.15 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2021 License: BSD-3-Clause Imports: 12 Imported by: 0

README

fatchoy

Golang Game Server Kit

Gung Hay Fat Choy(恭喜發財)

go get gopkg.in/qchencc/fatchoy.v1

各目录说明

目录 描述
log 日志
debug 调试API
codec 编解码
codes 错误码
sched 执行器
secure 密码生成
packet 消息结构
qnet 网络通信
discovery 服务发现
x 工具包
包名规范
  • API接口除非Must否则不使用panic抛出错误;
  • 使用下划线分隔的小写字母,并使用有意义的缩写
  • 包名要见文知义,让人看名字就知道这个包大体用来干什么的,避免太通用的名称(如common,util,misc)

参考 package names

规范

Git提交规范
<scope>: subject
<blank line>
<body>
  • scope: 是本次commit涉及了哪些模块
  • subject:本次commit的简单描述,仅一行
  • body: 对本次 commit 的详细描述,可以分成多行

大体是参考[Angular的规范](doc/Git Commit Message Conventions.docx),但不必全套照搬, 大致要注意以下几点:

  • 提交的commit message要考虑reviewer的阅读体验,能让其迅速浏览完这一篇提交大概干了些什么;
  • 提交的描述文字一律使用中文,不要这次提交写英语下次提交又是中文,非外企实践全英文环境必要性不强;
版本号管理

一个版本号(如1.0.1)由major.minor.patch三部分组成

  • major: 主版本号
  • minor: 次版本号
  • patch: 修订号

一些约定:

  • 第一个初始开发版本使用0.1.0
  • 第一个可以对外发布的版本使用1.0.0

参考semantic version

Documentation

Index

Constants

View Source
const (
	SERVICE_ALL  = 0xFF
	INSTANCE_ALL = 0xFFFF
)
View Source
const (
	NodeServiceShift = 16
	NodeServiceMask  = 0xFF00FFFF
	NodeInstanceMask = 0xFFFF0000
	NodeTypeShift    = 31
)
View Source
const VERSION = "1.3.15"

Variables

View Source
var (
	ClockEpoch int64 = 1577836800 // 2020-01-01 00:00:00 UTC

)

Functions

func DateTime

func DateTime() string

func Now

func Now() time.Time

func NowString

func NowString() string

func StartClock

func StartClock()

开启时钟

func StopClock

func StopClock()

关闭时钟

func WallClock

func WallClock() *datetime.Clock

Types

type Endpoint

type Endpoint interface {
	MessageEndpoint

	RawConn() net.Conn
	Stats() *stats.Stats

	Go(EndpointFlag)

	// 加密解密
	SetEncryptPair(cipher.BlockCryptor, cipher.BlockCryptor)
}

网络连接端点

type EndpointFlag added in v1.1.0

type EndpointFlag uint32
const (
	EndpointReader     EndpointFlag = 0x01
	EndpointWriter     EndpointFlag = 0x02
	EndpointReadWriter EndpointFlag = 0x03
)

type EndpointMap

type EndpointMap struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

线程安全的endpoint map

func NewEndpointMap

func NewEndpointMap() *EndpointMap

func (*EndpointMap) Add

func (e *EndpointMap) Add(node NodeID, endpoint Endpoint)

func (*EndpointMap) Delete

func (e *EndpointMap) Delete(node NodeID) bool

func (*EndpointMap) Get

func (e *EndpointMap) Get(node NodeID) Endpoint

func (*EndpointMap) List

func (e *EndpointMap) List() []Endpoint

func (*EndpointMap) Range added in v1.3.15

func (e *EndpointMap) Range(f func(Endpoint) bool)

func (*EndpointMap) Reset

func (e *EndpointMap) Reset()

func (*EndpointMap) Size

func (e *EndpointMap) Size() int

type IPacket

type IPacket interface {
	Command() int32
	SetCommand(int32)

	Seq() int16
	SetSeq(int16)

	Type() PacketType
	SetType(PacketType)

	Flag() PacketFlag
	SetFlag(PacketFlag)

	Errno() int32
	SetErrno(ec int32)

	Refers() []NodeID
	SetRefers([]NodeID)

	Endpoint() MessageEndpoint
	SetEndpoint(MessageEndpoint)

	Clone() IPacket

	SetBody(v interface{})
	IBody() interface{}

	BodyToInt() int64
	BodyToFloat() float64
	BodyToString() string
	BodyToBytes() []byte

	DecodeTo(msg proto.Message) error
	Decode() error

	Reply(command int32, body interface{}) error
	ReplyMsg(ack proto.Message) error

	Refuse(errno int32) error
	RefuseWith(command, errno int32) error
}

定义应用层消息接口

type MessageEndpoint

type MessageEndpoint interface {
	NodeID() NodeID
	SetNodeID(NodeID)
	RemoteAddr() string

	// 发送消息
	SendPacket(IPacket) error

	// 关闭读/写
	Close() error
	ForceClose(error)
	IsClosing() bool

	SetUserData(interface{})
	UserData() interface{}
}

type NodeID

type NodeID uint32

节点号

func MakeNodeID

func MakeNodeID(service uint8, instance uint16) NodeID

func MustParseNodeID

func MustParseNodeID(s string) NodeID

func (NodeID) Instance

func (n NodeID) Instance() uint16

实例编号

func (NodeID) IsTypeBackend

func (n NodeID) IsTypeBackend() bool

func (NodeID) Service

func (n NodeID) Service() uint8

服务类型编号

func (NodeID) String

func (n NodeID) String() string

type NodeIDSet

type NodeIDSet = collections.OrderedIDSet

没有重复ID的有序集合

type PacketFlag

type PacketFlag uint8

消息标志位

const (
	PFlagCompressed PacketFlag = 0x01 // 压缩
	PFlagEncrypted  PacketFlag = 0x02 // 加密
	PFlagError      PacketFlag = 0x10 // 错误标记
)

type PacketHandler added in v1.3.5

type PacketHandler func(IPacket) error // 消息处理器

type PacketType

type PacketType int8

消息编码类型

const (
	PTypePacket PacketType = 0 // 应用消息
	PTypeRoute  PacketType = 1 // 路由消息
)

type Service

type Service interface {
	Type() int8
	Name() string

	NodeID() NodeID
	SetNodeID(id NodeID)

	ServiceContext() *ServiceContext

	Init(*ServiceContext) error
	Startup() error
}

定义应用层服务接口

type ServiceContext

type ServiceContext struct {
	// contains filtered or unexported fields
}

服务的上下文

func NewServiceContext

func NewServiceContext(ctx context.Context, srv Service, queueSize int) *ServiceContext

func (*ServiceContext) Close

func (c *ServiceContext) Close()

func (*ServiceContext) Context

func (c *ServiceContext) Context() context.Context

func (*ServiceContext) MessageQueue

func (c *ServiceContext) MessageQueue() chan IPacket

func (*ServiceContext) Service

func (c *ServiceContext) Service() Service

Directories

Path Synopsis
x
uuid
This package provides immutable UUID structs and the functions NewV3, NewV4, NewV5 and Parse() for generating versions 3, 4 and 5 UUIDs as specified in RFC 4122.
This package provides immutable UUID structs and the functions NewV3, NewV4, NewV5 and Parse() for generating versions 3, 4 and 5 UUIDs as specified in RFC 4122.

Jump to

Keyboard shortcuts

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