refactor(login): 重构登录服务中的会话管理

- 移除 LoginSidInfo 中的 CacheManager 调用,改为使用 session 包
- 更新 BlazingController 中的 SaveSession 调用,使用 session 包
- 删除 LoginService 中的 SaveSessionId 方法,简化会话管理逻辑
- 优化代码结构,提高可维护性和可测试性
This commit is contained in:
2025-07-04 19:02:14 +08:00
parent e04b859137
commit ddfe3e6c2c
4 changed files with 49 additions and 20 deletions

View File

@@ -1,6 +1,7 @@
package admin
import (
"blazing/common/data/session"
"blazing/cool"
baseservice "blazing/modules/base/service"
"blazing/modules/blazing/service"
@@ -72,7 +73,7 @@ func (c *BlazingController) GetSession(ctx context.Context, req *SessionReq) (re
res.Session = retsid
if err := biazing_service.SaveSessionId(sid, gconv.String(accountID)); err != nil {
if err := session.SaveSession(sid, gconv.String(accountID)); err != nil {
res.Code = 400
res.Msg = err.Error()
}

View File

@@ -3,15 +3,12 @@ package service
import (
"blazing/cool"
"blazing/modules/blazing/model"
"context"
"encoding/binary"
"encoding/hex"
"fmt"
"math/rand"
"strings"
"time"
"github.com/gogf/gf/v2/os/gctx"
"github.com/google/uuid"
)
@@ -27,16 +24,6 @@ func NewLoginServiceService() *LoginService {
}
}
func (s *LoginService) SaveSessionId(session string, userid string) error {
cool.CacheManager.Set(gctx.New(), strings.Trim(session, " "), userid, time.Hour*24)
// gsvc.SetRegistry(etcd.New(`127.0.0.1:2379`))
t, err := cool.CacheManager.Contains(context.Background(), strings.Trim(session, " "))
fmt.Println("前端获取", session, t, err)
return nil
}
func (s *LoginService) GetSessionId(accountID uint) (string, string, error) {
t1, _ := uuid.NewV7()