feat/modules: 更新模块引用并添加 Redis 配置

- 更新 go.work 文件,添加 modules 引用
- 修改 logic/main.go,增加 Redis 模式监听
- 更新 login/main.go,引入 modules 模块
- 修改 manifest/config/config.yaml,添加 Redis 配置信息
This commit is contained in:
2025-06-23 12:24:23 +08:00
parent cc9f1fb45a
commit b93897f0a4
23 changed files with 987 additions and 855 deletions

View File

@@ -0,0 +1,76 @@
package admin
import (
baseservice "blazing/modules/base/service"
"blazing/modules/blazing/service"
"context"
"crypto/sha256"
"encoding/hex"
"fmt"
"strings"
"time"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gconv"
)
type SessionReq struct {
g.Meta `path:"/getSessionByAuth" method:"GET"`
Email string `json:"email" v:"required|email"`
Password string `json:"password" v:"required"`
}
type SessionRes struct {
Msg string `json:"msg"`
Code int `json:"code"`
Session string `json:"session"`
}
func (c *BlazingController) GetSession(ctx context.Context, req *SessionReq) (res *SessionRes, err error) {
// res = &DemoSampleWelcomeRes{
// BaseRes: cool.Ok("Welcome to Cool Admin Go"),
// Data: gjson.New(`{"name": "Cool Admin Go", "age":0}`),
// }
res = &SessionRes{
Msg: "success",
Code: 200,
Session: ""}
if err := g.Validator().Data(req).Run(ctx); err != nil {
fmt.Println(err)
res.Code = 400
res.Msg = err.Error()
}
res1, err := baseservice.NewBaseSysUserService().GetSession(req.Email, req.Password)
if err != nil {
res.Code = 400
res.Msg = err.Error()
}
accountID := res1.ID
// 生成SID
sidInfo := fmt.Sprintf("%d%d", accountID, time.Now().UnixNano())
hash := sha256.Sum256([]byte(sidInfo))
sidByte := hex.EncodeToString(hash[:])
// 确保长度为48字符
if len(sidByte) < 48 {
sidByte = sidByte + strings.Repeat("0", 48-len(sidByte))
} else {
sidByte = sidByte[:48]
}
// UID拼接SID
hex8 := fmt.Sprintf("%08X", int(accountID&0xFFFFFFFF))
res.Session = hex8 + sidByte[8:]
// 保存后端校验的SID
backendSID := res.Session[8 : len(res.Session)-8]
if err := service.NewLoginServiceService().SaveSessionId(backendSID, gconv.String(accountID)); err != nil {
res.Code = 400
res.Msg = err.Error()
}
return
}

View File

@@ -0,0 +1,55 @@
package admin
import (
"context"
"fmt"
"blazing/cool"
"blazing/modules/blazing/service"
"github.com/gogf/gf/v2/frame/g"
)
type BlazingController struct {
*cool.Controller
}
func init() {
var demo_sample_controller = &BlazingController{
&cool.Controller{
Prefix: "/seer/game",
Api: []string{},
Service: service.NewDemoSampleService(),
},
}
// 注册路由
cool.RegisterController(demo_sample_controller)
}
// 增加 Welcome 演示 方法
type RegReq struct {
g.Meta `path:"/reg" method:"POST"`
Email string `json:"email" v:"required|email"`
Password string `json:"password" v:"required"`
}
type RegRes struct {
*cool.BaseRes
Data interface{} `json:"data"`
}
func (c *BlazingController) Reg(ctx context.Context, req *RegReq) (res *cool.BaseRes, err error) {
// res = &DemoSampleWelcomeRes{
// BaseRes: cool.Ok("Welcome to Cool Admin Go"),
// Data: gjson.New(`{"name": "Cool Admin Go", "age":0}`),
// }
if err := g.Validator().Data(req).Run(ctx); err != nil {
fmt.Println(err)
res = cool.Ok(err)
} else {
res = cool.Ok("注册成功")
}
return
}

View File

@@ -0,0 +1,5 @@
package controller
import (
_ "blazing/modules/blazing/controller/admin"
)