feat/modules: 更新模块引用并添加 Redis 配置
- 更新 go.work 文件,添加 modules 引用 - 修改 logic/main.go,增加 Redis 模式监听 - 更新 login/main.go,引入 modules 模块 - 修改 manifest/config/config.yaml,添加 Redis 配置信息
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
# blazing
|
# blazing
|
||||||
|
|
||||||
这是骄阳号开发团队的开源项目,请勿用于商业用途。
|
这是骄阳号开发团队的开源项目,请勿用于商业用途。
|
||||||
|
在软件开发中,repo、impl、mapper 和 model 是常见的分层架构组件
|
||||||
## 项目介绍
|
## 项目介绍
|
||||||
|
|
||||||
## seer-project
|
## seer-project
|
||||||
|
|||||||
3
go.work
3
go.work
@@ -8,8 +8,9 @@ use (
|
|||||||
./common/serialize/sturc
|
./common/serialize/sturc
|
||||||
./logic
|
./logic
|
||||||
./login
|
./login
|
||||||
|
./modules
|
||||||
./modules/base
|
./modules/base
|
||||||
./modules/demo
|
./modules/blazing
|
||||||
./modules/dict
|
./modules/dict
|
||||||
./modules/space
|
./modules/space
|
||||||
./modules/task
|
./modules/task
|
||||||
|
|||||||
@@ -6,11 +6,14 @@ import (
|
|||||||
"blazing/common/socket"
|
"blazing/common/socket"
|
||||||
"blazing/common/socket/cmd"
|
"blazing/common/socket/cmd"
|
||||||
"blazing/common/socket/handler"
|
"blazing/common/socket/handler"
|
||||||
|
"blazing/cool"
|
||||||
"blazing/logic/controller"
|
"blazing/logic/controller"
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/os/gctx"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -20,7 +23,9 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
if cool.IsRedisMode {
|
||||||
|
go cool.ListenFunc(gctx.New())
|
||||||
|
}
|
||||||
Start("27777") //注入service
|
Start("27777") //注入service
|
||||||
}
|
}
|
||||||
func Start(port string) {
|
func Start(port string) {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import (
|
|||||||
|
|
||||||
//_ "blazing/contrib/drivers/pgsql"
|
//_ "blazing/contrib/drivers/pgsql"
|
||||||
|
|
||||||
_ "blazing/modules/base"
|
_ "blazing/modules"
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/os/gctx"
|
"github.com/gogf/gf/v2/os/gctx"
|
||||||
|
|
||||||
|
|||||||
@@ -43,8 +43,10 @@ database:
|
|||||||
# Redis 配置示例
|
# Redis 配置示例
|
||||||
redis:
|
redis:
|
||||||
cool:
|
cool:
|
||||||
address: "127.0.0.1:6379"
|
address: "159.75.107.160:6379"
|
||||||
db: 0
|
db: 0
|
||||||
|
pass: 154252
|
||||||
|
|
||||||
|
|
||||||
cool:
|
cool:
|
||||||
autoMigrate: true
|
autoMigrate: true
|
||||||
|
|||||||
@@ -27,7 +27,17 @@ func (s *BaseSysUserService) Person(userId uint) (res gdb.Record, err error) {
|
|||||||
res, err = m.Where("id = ?", userId).FieldsEx("password").One()
|
res, err = m.Where("id = ?", userId).FieldsEx("password").One()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
func (s *BaseSysUserService) GetSession(email string, password string) (res *model.BaseSysUser, err error) {
|
||||||
|
m := cool.DBM(s.Model)
|
||||||
|
|
||||||
|
m.Where("email = ?", email).Where("password=?", password).Where("status=?", 1).Scan(&res)
|
||||||
|
if res == nil {
|
||||||
|
err = gerror.New("账户或密码不正确~")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
func (s *BaseSysUserService) ModifyBefore(ctx context.Context, method string, param g.MapStrAny) (err error) {
|
func (s *BaseSysUserService) ModifyBefore(ctx context.Context, method string, param g.MapStrAny) (err error) {
|
||||||
if method == "Delete" {
|
if method == "Delete" {
|
||||||
// 禁止删除超级管理员
|
// 禁止删除超级管理员
|
||||||
@@ -200,7 +210,8 @@ func NewBaseSysUserService() *BaseSysUserService {
|
|||||||
Model: model.NewBaseSysUser(),
|
Model: model.NewBaseSysUser(),
|
||||||
InfoIgnoreProperty: "password",
|
InfoIgnoreProperty: "password",
|
||||||
UniqueKey: map[string]string{
|
UniqueKey: map[string]string{
|
||||||
"username": "用户名不能重复",
|
// "username": "用户名不能重复",
|
||||||
|
"email": "邮箱不能重复",
|
||||||
},
|
},
|
||||||
PageQueryOp: &cool.QueryOp{
|
PageQueryOp: &cool.QueryOp{
|
||||||
Select: "base_sys_user.*,dept.`name` as departmentName,GROUP_CONCAT( role.`name` ) AS `roleName`",
|
Select: "base_sys_user.*,dept.`name` as departmentName,GROUP_CONCAT( role.`name` ) AS `roleName`",
|
||||||
|
|||||||
76
modules/blazing/controller/admin/login.go
Normal file
76
modules/blazing/controller/admin/login.go
Normal 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
|
||||||
|
}
|
||||||
55
modules/blazing/controller/admin/reg.go
Normal file
55
modules/blazing/controller/admin/reg.go
Normal 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
|
||||||
|
}
|
||||||
5
modules/blazing/controller/controller.go
Normal file
5
modules/blazing/controller/controller.go
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "blazing/modules/blazing/controller/admin"
|
||||||
|
)
|
||||||
7
modules/blazing/demo.go
Normal file
7
modules/blazing/demo.go
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package demo
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "blazing/modules/blazing/controller"
|
||||||
|
_ "blazing/modules/blazing/model"
|
||||||
|
_ "blazing/modules/blazing/service"
|
||||||
|
)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
module blazing/modules/demo
|
module blazing/modules/blazing
|
||||||
|
|
||||||
go 1.18
|
go 1.18
|
||||||
|
|
||||||
@@ -3,7 +3,7 @@ package service
|
|||||||
import (
|
import (
|
||||||
"blazing/cool"
|
"blazing/cool"
|
||||||
|
|
||||||
"blazing/modules/demo/model"
|
"blazing/modules/blazing/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DemoGoodsService struct {
|
type DemoGoodsService struct {
|
||||||
@@ -3,7 +3,7 @@ package service
|
|||||||
import (
|
import (
|
||||||
"blazing/cool"
|
"blazing/cool"
|
||||||
|
|
||||||
"blazing/modules/demo/model"
|
"blazing/modules/blazing/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DemoSampleService struct {
|
type DemoSampleService struct {
|
||||||
21
modules/blazing/service/login.go
Normal file
21
modules/blazing/service/login.go
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"blazing/cool"
|
||||||
|
)
|
||||||
|
|
||||||
|
type LoginService struct {
|
||||||
|
*cool.Service
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewLoginServiceService() *LoginService {
|
||||||
|
return &LoginService{
|
||||||
|
&cool.Service{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *LoginService) SaveSessionId(session, userid string) error {
|
||||||
|
// gsvc.SetRegistry(etcd.New(`127.0.0.1:2379`))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
package admin
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"blazing/cool"
|
|
||||||
|
|
||||||
"blazing/modules/demo/service"
|
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/encoding/gjson"
|
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
|
||||||
)
|
|
||||||
|
|
||||||
type DemoSampleController struct {
|
|
||||||
*cool.Controller
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
var demo_sample_controller = &DemoSampleController{
|
|
||||||
&cool.Controller{
|
|
||||||
Prefix: "/admin/demo/demo_sample",
|
|
||||||
Api: []string{"Add", "Delete", "Update", "Info", "List", "Page"},
|
|
||||||
Service: service.NewDemoSampleService(),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
// 注册路由
|
|
||||||
cool.RegisterController(demo_sample_controller)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 增加 Welcome 演示 方法
|
|
||||||
type DemoSampleWelcomeReq struct {
|
|
||||||
g.Meta `path:"/welcome" method:"GET"`
|
|
||||||
}
|
|
||||||
type DemoSampleWelcomeRes struct {
|
|
||||||
*cool.BaseRes
|
|
||||||
Data interface{} `json:"data"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *DemoSampleController) Welcome(ctx context.Context, req *DemoSampleWelcomeReq) (res *DemoSampleWelcomeRes, err error) {
|
|
||||||
res = &DemoSampleWelcomeRes{
|
|
||||||
BaseRes: cool.Ok("Welcome to Cool Admin Go"),
|
|
||||||
Data: gjson.New(`{"name": "Cool Admin Go", "age":0}`),
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package controller
|
|
||||||
|
|
||||||
import (
|
|
||||||
_ "blazing/modules/demo/controller/admin"
|
|
||||||
)
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package demo
|
|
||||||
|
|
||||||
import (
|
|
||||||
_ "blazing/modules/demo/controller"
|
|
||||||
_ "blazing/modules/demo/model"
|
|
||||||
_ "blazing/modules/demo/service"
|
|
||||||
)
|
|
||||||
6
modules/go.mod
Normal file
6
modules/go.mod
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
module blazing/modules
|
||||||
|
|
||||||
|
go 1.19
|
||||||
|
|
||||||
|
require (
|
||||||
|
)
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package blazing/modules
|
package modules
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "blazing/modules/base"
|
_ "blazing/modules/base"
|
||||||
_ "blazing/modules/demo"
|
_ "blazing/modules/blazing"
|
||||||
_ "blazing/modules/dict"
|
_ "blazing/modules/dict"
|
||||||
_ "blazing/modules/space"
|
_ "blazing/modules/space"
|
||||||
_ "blazing/modules/task"
|
_ "blazing/modules/task"
|
||||||
|
|||||||
Reference in New Issue
Block a user