mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-10-15 22:43:45 +08:00
发布v2.8.4版本,更新内容请查看:https://github.com/bufanyun/hotgo/tree/v2.0/docs/guide-zh-CN/addon-version-upgrade.md
This commit is contained in:
49
server/internal/logic/tcpserver/example_handle.go
Normal file
49
server/internal/logic/tcpserver/example_handle.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package tcpserver
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"hotgo/api/servmsg"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/library/network/tcp"
|
||||
"hotgo/internal/model/input/servmsgin"
|
||||
)
|
||||
|
||||
// OnExampleHello 一个tcp请求例子
|
||||
func (s *sTCPServer) OnExampleHello(ctx context.Context, req *servmsg.ExampleHelloReq) {
|
||||
var (
|
||||
conn = tcp.ConnFromCtx(ctx)
|
||||
res = new(servmsg.ExampleHelloRes)
|
||||
data = new(servmsgin.ExampleHelloModel)
|
||||
)
|
||||
|
||||
if conn == nil {
|
||||
g.Log().Warningf(ctx, "conn is nil.")
|
||||
return
|
||||
}
|
||||
|
||||
if conn.Auth == nil {
|
||||
res.SetError(gerror.New("连接未认证,请确认已登录成功!"))
|
||||
conn.Send(ctx, res)
|
||||
return
|
||||
}
|
||||
|
||||
data.Desc = fmt.Sprintf("Hello %v, 你的APPID:%v,当前HotGo版本:%v,你成功请求了`servmsg.ExampleHelloReq`接口!", req.Name, conn.Auth.AppId, consts.VersionApp)
|
||||
data.Timestamp = gtime.Now()
|
||||
res.Data = data
|
||||
conn.Send(ctx, res)
|
||||
}
|
||||
|
||||
// OnExampleRPCHello 一个rpc请求例子
|
||||
func (s *sTCPServer) OnExampleRPCHello(ctx context.Context, req *servmsg.ExampleRPCHelloReq) (res *servmsg.ExampleRPCHelloRes, err error) {
|
||||
var data = new(servmsgin.ExampleHelloModel)
|
||||
data.Desc = fmt.Sprintf("Hello %v, 当前HotGo版本:%v,你成功请求了`servmsg.ExampleRPCHelloReq`接口!", req.Name, consts.VersionApp)
|
||||
data.Timestamp = gtime.Now()
|
||||
|
||||
res = new(servmsg.ExampleRPCHelloRes)
|
||||
res.Data = data
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user