发布v2.4.4版本,本次为优化版本。更新内容请查看:https://github.com/bufanyun/hotgo/blob/v2.0/docs/guide-zh-CN/start-update-log.md

This commit is contained in:
孟帅
2023-03-16 15:35:02 +08:00
parent 1acc6d17c4
commit 2c27be12fd
16 changed files with 309 additions and 282 deletions

View File

@@ -240,22 +240,31 @@ func (s *sSysGenCodes) TableSelect(ctx context.Context, in sysin.GenCodesTableSe
continue
}
newValue := v.Value
if config.Prefix != "" {
newValue = gstr.SubStrFromEx(v.Value, config.Prefix)
}
if newValue == "" {
err = gerror.Newf("表名[%v]前缀必须和配置中的前缀设置[%v] 保持一致", v.Value, config.Prefix)
return
}
// 如果是插件模块,则移除掉插件表前缀
defVarName := gstr.SubStrFromEx(v.Value, config.Prefix)
bt, err := gregex.Replace(patternStr, []byte(repStr), []byte(defVarName))
bt, err := gregex.Replace(patternStr, []byte(repStr), []byte(newValue))
if err != nil {
err = gerror.Newf("表名[%v] gregex.Replace err:%v", v.Value, err.Error())
break
}
defVarName = gstr.CaseCamel(string(bt))
row := new(sysin.GenCodesTableSelectModel)
row = v
row.DefTableComment = v.Label
row.DaoName = gstr.CaseCamel(gstr.SubStrFromEx(v.Value, config.Prefix))
row.DefVarName = defVarName
row.DefAlias = gstr.CaseCamelLower(gstr.SubStrFromEx(v.Value, config.Prefix))
row.DaoName = gstr.CaseCamel(newValue)
row.DefVarName = gstr.CaseCamel(string(bt))
row.DefAlias = gstr.CaseCamelLower(newValue)
row.Name = fmt.Sprintf("%s (%s)", v.Value, v.Label)
row.Label = row.Name
res = append(res, row)
}
return res, nil

View File

@@ -198,7 +198,7 @@ func (s *sSysLog) AnalysisLog(ctx context.Context) entity.SysLog {
ipData, err := location.GetLocation(ctx, clientIp)
if err != nil {
g.Log().Errorf(ctx, "location.GetLocation err:%+v", err)
g.Log().Infof(ctx, "location.GetLocation clientIp:%v, err:%+v", clientIp, err)
}
if ipData == nil {
ipData = new(location.IpLocationData)

View File

@@ -2,12 +2,8 @@ package tcpclient
import (
"context"
"github.com/gogf/gf/v2/errors/gcode"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gcron"
"github.com/gogf/gf/v2/util/gconv"
"hotgo/internal/library/network/tcp"
"hotgo/internal/model/input/msgin"
"hotgo/internal/service"
"hotgo/utility/simple"
)
@@ -37,8 +33,8 @@ func (s *sTCPAuth) Start(ctx context.Context) {
AppId: "mengshuai",
SecretKey: "123456",
},
LoginEvent: s.loginEvent,
CloseEvent: s.closeEvent,
LoginEvent: s.onLoginEvent,
CloseEvent: s.onCloseEvent,
})
if err != nil {
g.Log().Infof(ctx, "TCPAuth NewClient fail%+v", err)
@@ -48,7 +44,7 @@ func (s *sTCPAuth) Start(ctx context.Context) {
s.client = client
err = s.client.RegisterRouter(map[string]tcp.RouterHandler{
"ResponseAuthSummary": s.onResponseAuthSummary, // 获取授权信息
// ...
})
if err != nil {
@@ -63,7 +59,7 @@ func (s *sTCPAuth) Start(ctx context.Context) {
})
}
// Stop 关闭服务
// Stop 停止服务
func (s *sTCPAuth) Stop(ctx context.Context) {
if s.client != nil {
s.client.Stop()
@@ -71,40 +67,17 @@ func (s *sTCPAuth) Stop(ctx context.Context) {
}
}
func (s *sTCPAuth) loginEvent() {
// 登录成功后立即请求一次授权信息
s.client.Write(&msgin.AuthSummary{})
// 定时检查授权
gcron.Add(s.client.Ctx, "@every 1200s", func(ctx context.Context) {
if !s.client.IsLogin {
g.Log().Infof(ctx, "TCPAuthVerify client is not logged in, skipped")
return
}
s.client.Write(&msgin.AuthSummary{})
}, "TCPAuthVerify")
// IsLogin 是否已登录认证
func (s *sTCPAuth) IsLogin() bool {
return s.client.IsLogin
}
func (s *sTCPAuth) closeEvent() {
// 关闭连接后,删除定时检查授权
gcron.Remove("TCPAuthVerify")
// onLoginEvent 登录认证成功事件
func (s *sTCPAuth) onLoginEvent() {
// ...
}
func (s *sTCPAuth) onResponseAuthSummary(args ...interface{}) {
var in *msgin.ResponseAuthSummary
if err := gconv.Scan(args[0], &in); err != nil {
s.client.Logger.Infof(s.client.Ctx, "ResponseAuthSummary message Scan failed:%+v, args:%+v", err, args[0])
return
}
s.client.Logger.Infof(s.client.Ctx, "onResponseAuthSummary in:%+v", *in)
// 授权异常
if in.Code != gcode.CodeOK.Code() {
s.client.Logger.Infof(s.client.Ctx, "onResponseAuthSummary authorization verification failed:%+v", in.Message)
s.client.Destroy()
return
}
// 授权通过
// 后续可以做一些操作...
// onCloseEvent 连接关闭回调事件
func (s *sTCPAuth) onCloseEvent() {
// ...
}