This commit is contained in:
孟帅
2023-07-20 18:01:10 +08:00
parent 9113fc5297
commit 373d9627fb
492 changed files with 12170 additions and 6982 deletions

View File

@@ -1,24 +1,54 @@
// Package tcpclient
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package tcpclient
import (
"context"
"github.com/gogf/gf/v2/util/gconv"
"hotgo/internal/model/input/msgin"
"github.com/gogf/gf/v2/frame/g"
"hotgo/api/servmsg"
)
// OnResponseAuthSummary 获取授权信息
func (s *sAuthClient) OnResponseAuthSummary(ctx context.Context, args ...interface{}) {
var in *msgin.ResponseAuthSummary
if err := gconv.Scan(args[0], &in); err != nil {
s.client.Logger.Warningf(ctx, "OnResponseAuthSummary Scan err:%+v", err)
return
}
if err := in.GetError(); err != nil {
s.client.Logger.Warningf(ctx, "OnResponseAuthSummary GetError:%+v", err)
// OnResponseAuthSummary 响应授权信息
func (s *sAuthClient) OnResponseAuthSummary(ctx context.Context, req *servmsg.AuthSummaryRes) {
if err := req.GetError(); err != nil {
g.Log().Warningf(ctx, "OnResponseAuthSummary GetError:%+v", err)
return
}
// 拿到授权的数据,可以是一些动态的功能、路由、权限控制等
s.summary = in.Data
s.summary = req.Data
}
// OnResponseExampleHello 一个tcp请求例子
func (s *sAuthClient) OnResponseExampleHello(ctx context.Context, req *servmsg.ExampleHelloRes) {
if err := req.GetError(); err != nil {
g.Log().Warningf(ctx, "OnResponseExampleHello GetError:%+v", err)
return
}
g.Log().Infof(ctx, "OnResponseExampleHello data:%+v", req.Data)
}
// testExample 测试例子
func (s *sAuthClient) testExample(ctx context.Context) {
// 发起tcp请求
// 异步执行,服务端返回消息后会转到`OnResponseExampleHello`中
s.client.Send(ctx, &servmsg.ExampleHelloReq{
Name: "Tom",
})
// 发起rpc请求
// 同步执行,阻塞等待服务端返回消息
var req = &servmsg.ExampleRPCHelloReq{
Name: "Tony",
}
var res *servmsg.ExampleRPCHelloRes
if err := s.client.RequestScan(ctx, req, &res); err != nil {
g.Log().Warningf(ctx, "client.Request ExampleRPCHelloReq err:%+v", err)
return
}
g.Log().Infof(ctx, "ExampleRPCHelloRes data:%+v", res.Data)
}