refactor(rpc): 重构 RPC 客户端并添加重连机制
- 更新了 RPC 客户端的初始化和重连逻辑 - 添加了重连函数和最大重试次数的配置 - 优化了与服务器的连接管理 - 调整了端口相关的数据类型
This commit is contained in:
@@ -3,10 +3,13 @@ package admin
|
||||
import (
|
||||
"context"
|
||||
|
||||
"blazing/common/data/share"
|
||||
"blazing/cool"
|
||||
|
||||
"blazing/modules/base/service"
|
||||
|
||||
blazing_service "blazing/modules/blazing/service"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
@@ -30,9 +33,35 @@ type UserMoveReq struct {
|
||||
g.Meta `path:"/move" method:"GET"`
|
||||
Authorization string `json:"Authorization" in:"header"`
|
||||
}
|
||||
type SessionReq struct {
|
||||
g.Meta `path:"/getSession" method:"GET"`
|
||||
Authorization string `json:"Authorization" in:"header"`
|
||||
}
|
||||
|
||||
func (c *BaseSysUserController) Move(ctx context.Context, req *UserMoveReq) (res *cool.BaseRes, err error) {
|
||||
err = service.NewBaseSysUserService().Move(ctx)
|
||||
res = cool.Ok(nil)
|
||||
return
|
||||
}
|
||||
|
||||
func (c *BaseSysUserController) GetSession(ctx context.Context, req *SessionReq) (res *cool.BaseRes, err error) {
|
||||
|
||||
t := cool.GetAdmin(ctx)
|
||||
if t == nil || t.UserId == 0 {
|
||||
|
||||
return cool.Fail("未登录"), nil
|
||||
}
|
||||
retsid, sid, err := blazing_service.NewLoginServiceService().GetSessionId(t.UserId)
|
||||
if err != nil {
|
||||
return cool.Fail(err.Error()), nil
|
||||
|
||||
}
|
||||
res = cool.Ok(nil)
|
||||
res.Data = retsid
|
||||
|
||||
if err := share.ShareManager.SaveSession(sid, uint32(t.UserId)); err != nil {
|
||||
return cool.Fail(err.Error()), nil
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ const TableNameServerList = "server_list"
|
||||
// ServerList mapped from table <server_list>
|
||||
type ServerList struct {
|
||||
*cool.Model
|
||||
OnlineID uint32 `gorm:"column:online_id;comment:'在线ID';uniqueIndex" json:"online_id"`
|
||||
OnlineID uint16 `gorm:"column:online_id;comment:'在线ID';uniqueIndex" json:"online_id"`
|
||||
//IP string `gorm:"type:varchar(16);comment:'服务器IP'" json:"ip"`
|
||||
Port uint16 `gorm:"comment:'端口号,通常是小整数'" json:"port"`
|
||||
//IsOpen bool `gorm:"default:true;not null;comment:'服务器是否开启,默认为开启状态'" json:"is_open"`
|
||||
|
||||
@@ -50,10 +50,10 @@ func (s *LoginService) GetSessionId(accountID uint) (string, string, error) {
|
||||
// /t1.
|
||||
// 以上过程只需全局一次,且应在生成ID之前完成。
|
||||
}
|
||||
func (s *LoginService) SetServerID(OnlineID uint32, Port uint16, t *struct {
|
||||
func (s *LoginService) SetServerID(OnlineID uint16, Port uint16, t *struct {
|
||||
Kick func(uint32) error
|
||||
|
||||
RegisterLogic func(uint16) error
|
||||
RegisterLogic func(uint16, uint16) error
|
||||
}) error {
|
||||
|
||||
m := cool.DBM(s.Model).Where("online_id", OnlineID)
|
||||
|
||||
Reference in New Issue
Block a user