Titan Panda
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 283 additions and 87 deletions
-
5.gitignore
-
4Makefile
-
39README.md
-
21examples/zinx_client/Makefile
-
22examples/zinx_client/build.sh
-
1examples/zinx_client/version
-
3examples/zinx_server/build.sh
-
5go.mod
-
6go.sum
-
11utils/globalobj.go
-
47ziface/iconnection.go
-
13ziface/iconnmanager.go
-
13ziface/idatapack.go
-
13ziface/imessage.go
-
13ziface/imsghandler.go
-
13ziface/irequest.go
-
13ziface/irouter.go
-
42ziface/iserver.go
-
9zlog/stdzlog.go
-
39zlog/zlogger.go
-
38zlog/zlogger_test.go
@ -1,3 +1,6 @@ |
|||||
.idea |
.idea |
||||
|
.vscode |
||||
|
|
||||
/zinx_app_demo/mmo_game/game_client/client_Data/ |
/zinx_app_demo/mmo_game/game_client/client_Data/ |
||||
/zinx_app_demt/mmo_game/mmo_game_log/ |
|
||||
|
/zinx_app_demt/mmo_game/mmo_game_log/ |
||||
|
*.log |
@ -0,0 +1,21 @@ |
|||||
|
PROJECT_NAME:=zinx_client |
||||
|
VERSION:=v1 |
||||
|
|
||||
|
|
||||
|
.PHONY: image run build clean |
||||
|
|
||||
|
build: |
||||
|
bash build.sh ${PROJECT_NAME} |
||||
|
|
||||
|
image: |
||||
|
docker build -t ${PROJECT_NAME}:${VERSION} . |
||||
|
|
||||
|
run: |
||||
|
docker run -itd \
|
||||
|
-p 8999:8999 \
|
||||
|
${PROJECT_NAME}:${VERSION} |
||||
|
|
||||
|
|
||||
|
clean: |
||||
|
rm -rf ${PROJECT_NAME} |
||||
|
|
@ -0,0 +1,22 @@ |
|||||
|
#!/bin/bash |
||||
|
|
||||
|
set -e |
||||
|
|
||||
|
APP_NAME=$1 |
||||
|
APP_VERSION=v$(cat version) |
||||
|
BUILD_VERSION=$(git log -1 --oneline) |
||||
|
BUILD_TIME=$(date "+%FT%T%z") |
||||
|
GIT_REVISION=$(git rev-parse --short HEAD) |
||||
|
GIT_BRANCH=$(git name-rev --name-only HEAD) |
||||
|
GO_VERSION=$(go version) |
||||
|
|
||||
|
|
||||
|
go build -ldflags " \ |
||||
|
-X 'main.AppName=${APP_NAME}' \ |
||||
|
-X 'main.AppVersion=${APP_VERSION}' \ |
||||
|
-X 'main.BuildVersion=${BUILD_VERSION//\'/_}' \ |
||||
|
-X 'main.BuildTime=${BUILD_TIME}' \ |
||||
|
-X 'main.GitRevision=${GIT_REVISION}' \ |
||||
|
-X 'main.GitBranch=${GIT_BRANCH}' \ |
||||
|
-X 'main.GoVersion=${GO_VERSION}' \ |
||||
|
" -o $APP_NAME |
@ -0,0 +1 @@ |
|||||
|
v 1.0.0 |
@ -1,2 +1,8 @@ |
|||||
github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I= |
github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I= |
||||
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= |
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= |
||||
|
golang.org/x/net v0.0.0-20210415231046-e915ea6b2b7d/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8= |
||||
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= |
||||
|
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= |
||||
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= |
||||
|
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= |
||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= |
@ -1,23 +1,27 @@ |
|||||
|
// Package ziface 主要提供zinx全部抽象层接口定义.
|
||||
|
// 包括:
|
||||
|
// IServer 服务mod接口
|
||||
|
// IRouter 路由mod接口
|
||||
|
// IConnection 连接mod层接口
|
||||
|
// IMessage 消息mod接口
|
||||
|
// IDataPack 消息拆解接口
|
||||
|
// IMsgHandler 消息处理及协程池接口
|
||||
|
//
|
||||
|
// 当前文件描述:
|
||||
|
// @Title iserver.go
|
||||
|
// @Description 提供Server抽象层全部接口声明
|
||||
|
// @Author Aceld - Thu Mar 11 10:32:29 CST 2019
|
||||
package ziface |
package ziface |
||||
|
|
||||
//定义服务器接口
|
|
||||
|
//定义服务接口
|
||||
type IServer interface { |
type IServer interface { |
||||
//启动服务器方法
|
|
||||
Start() |
|
||||
//停止服务器方法
|
|
||||
Stop() |
|
||||
//开启业务服务方法
|
|
||||
Serve() |
|
||||
//路由功能:给当前服务注册一个路由业务方法,供客户端链接处理使用
|
|
||||
AddRouter(msgID uint32, router IRouter) |
|
||||
//得到链接管理
|
|
||||
GetConnMgr() IConnManager |
|
||||
//设置该Server的连接创建时Hook函数
|
|
||||
SetOnConnStart(func(IConnection)) |
|
||||
//设置该Server的连接断开时的Hook函数
|
|
||||
SetOnConnStop(func(IConnection)) |
|
||||
//调用连接OnConnStart Hook函数
|
|
||||
CallOnConnStart(conn IConnection) |
|
||||
//调用连接OnConnStop Hook函数
|
|
||||
CallOnConnStop(conn IConnection) |
|
||||
|
Start() //启动服务器方法
|
||||
|
Stop() //停止服务器方法
|
||||
|
Serve() //开启业务服务方法
|
||||
|
AddRouter(msgID uint32, router IRouter) //路由功能:给当前服务注册一个路由业务方法,供客户端链接处理使用
|
||||
|
GetConnMgr() IConnManager //得到链接管理
|
||||
|
SetOnConnStart(func(IConnection)) //设置该Server的连接创建时Hook函数
|
||||
|
SetOnConnStop(func(IConnection)) //设置该Server的连接断开时的Hook函数
|
||||
|
CallOnConnStart(conn IConnection) //调用连接OnConnStart Hook函数
|
||||
|
CallOnConnStop(conn IConnection) //调用连接OnConnStop Hook函数
|
||||
} |
} |
@ -1,39 +1,39 @@ |
|||||
package zlog |
|
||||
|
package zlog_test |
||||
|
|
||||
import ( |
import ( |
||||
|
"github.com/aceld/zinx/zlog" |
||||
"testing" |
"testing" |
||||
) |
) |
||||
|
|
||||
func TestStdZLog(t *testing.T) { |
func TestStdZLog(t *testing.T) { |
||||
|
|
||||
//测试 默认debug输出
|
//测试 默认debug输出
|
||||
Debug("zinx debug content1") |
|
||||
Debug("zinx debug content2") |
|
||||
|
zlog.Debug("zinx debug content1") |
||||
|
zlog.Debug("zinx debug content2") |
||||
|
|
||||
Debugf(" zinx debug a = %d\n", 10) |
|
||||
|
zlog.Debugf(" zinx debug a = %d\n", 10) |
||||
|
|
||||
//设置log标记位,加上长文件名称 和 微秒 标记
|
//设置log标记位,加上长文件名称 和 微秒 标记
|
||||
ResetFlags(BitDate | BitLongFile | BitLevel) |
|
||||
Info("zinx info content") |
|
||||
|
zlog.ResetFlags(zlog.BitDate | zlog.BitLongFile | zlog.BitLevel) |
||||
|
zlog.Info("zinx info content") |
||||
|
|
||||
//设置日志前缀,主要标记当前日志模块
|
//设置日志前缀,主要标记当前日志模块
|
||||
SetPrefix("MODULE") |
|
||||
Error("zinx error content") |
|
||||
|
zlog.SetPrefix("MODULE") |
||||
|
zlog.Error("zinx error content") |
||||
|
|
||||
//添加标记位
|
//添加标记位
|
||||
AddFlag(BitShortFile | BitTime) |
|
||||
Stack(" Zinx Stack! ") |
|
||||
|
zlog.AddFlag(zlog.BitShortFile | zlog.BitTime) |
||||
|
zlog.Stack(" Zinx Stack! ") |
||||
|
|
||||
//设置日志写入文件
|
//设置日志写入文件
|
||||
SetLogFile("./log", "testfile.log") |
|
||||
Debug("===> zinx debug content ~~666") |
|
||||
Debug("===> zinx debug content ~~888") |
|
||||
Error("===> zinx Error!!!! ~~~555~~~") |
|
||||
|
zlog.SetLogFile("./log", "testfile.log") |
||||
|
zlog.Debug("===> zinx debug content ~~666") |
||||
|
zlog.Debug("===> zinx debug content ~~888") |
||||
|
zlog.Error("===> zinx Error!!!! ~~~555~~~") |
||||
|
|
||||
//关闭debug调试
|
//关闭debug调试
|
||||
CloseDebug() |
|
||||
Debug("===> 我不应该出现~!") |
|
||||
Debug("===> 我不应该出现~!") |
|
||||
Error("===> zinx Error after debug close !!!!") |
|
||||
|
|
||||
|
zlog.CloseDebug() |
||||
|
zlog.Debug("===> 我不应该出现~!") |
||||
|
zlog.Debug("===> 我不应该出现~!") |
||||
|
zlog.Error("===> zinx Error after debug close !!!!") |
||||
} |
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue