refactor: 包名变更ctx -> req

This commit is contained in:
meilin.huang
2023-01-14 16:29:52 +08:00
parent 2a91cdb67a
commit 594ca43505
46 changed files with 395 additions and 401 deletions

View File

@@ -18,8 +18,8 @@ require (
golang.org/x/crypto v0.5.0 // ssh golang.org/x/crypto v0.5.0 // ssh
gopkg.in/yaml.v3 v3.0.1 gopkg.in/yaml.v3 v3.0.1
// gorm // gorm
gorm.io/driver/mysql v1.4.4 gorm.io/driver/mysql v1.4.5
gorm.io/gorm v1.24.2 gorm.io/gorm v1.24.3
) )
require ( require (

View File

@@ -2,9 +2,9 @@ package initialize
import ( import (
sysapp "mayfly-go/internal/sys/application" sysapp "mayfly-go/internal/sys/application"
"mayfly-go/pkg/ctx" "mayfly-go/pkg/req"
) )
func InitSaveLogFunc() ctx.SaveLogFunc { func InitSaveLogFunc() req.SaveLogFunc {
return sysapp.GetSyslogApp().SaveFromReq return sysapp.GetSyslogApp().SaveFromReq
} }

View File

@@ -2,14 +2,14 @@ package api
import ( import (
"mayfly-go/pkg/biz" "mayfly-go/pkg/biz"
"mayfly-go/pkg/ctx" "mayfly-go/pkg/req"
"mayfly-go/pkg/utils" "mayfly-go/pkg/utils"
) )
type Common struct { type Common struct {
} }
func (i *Common) RasPublicKey(rc *ctx.ReqCtx) { func (i *Common) RasPublicKey(rc *req.Ctx) {
publicKeyStr, err := utils.GetRsaPublicKey() publicKeyStr, err := utils.GetRsaPublicKey()
biz.ErrIsNilAppendErr(err, "rsa生成公私钥失败") biz.ErrIsNilAppendErr(err, "rsa生成公私钥失败")
rc.ResData = publicKeyStr rc.ResData = publicKeyStr

View File

@@ -10,7 +10,7 @@ import (
redisapp "mayfly-go/internal/redis/application" redisapp "mayfly-go/internal/redis/application"
redisentity "mayfly-go/internal/redis/domain/entity" redisentity "mayfly-go/internal/redis/domain/entity"
tagapp "mayfly-go/internal/tag/application" tagapp "mayfly-go/internal/tag/application"
"mayfly-go/pkg/ctx" "mayfly-go/pkg/req"
) )
type Index struct { type Index struct {
@@ -21,7 +21,7 @@ type Index struct {
MongoApp mongoapp.Mongo MongoApp mongoapp.Mongo
} }
func (i *Index) Count(rc *ctx.ReqCtx) { func (i *Index) Count(rc *req.Ctx) {
accountId := rc.LoginAccount.Id accountId := rc.LoginAccount.Id
tagIds := i.TagApp.ListTagIdByAccountId(accountId) tagIds := i.TagApp.ListTagIdByAccountId(accountId)

View File

@@ -2,7 +2,7 @@ package router
import ( import (
"mayfly-go/internal/common/api" "mayfly-go/internal/common/api"
"mayfly-go/pkg/ctx" "mayfly-go/pkg/req"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@@ -13,7 +13,7 @@ func InitCommonRouter(router *gin.RouterGroup) {
{ {
// 获取公钥 // 获取公钥
common.GET("public-key", func(g *gin.Context) { common.GET("public-key", func(g *gin.Context) {
ctx.NewReqCtxWithGin(g). req.NewCtxWithGin(g).
WithNeedToken(false). WithNeedToken(false).
Handle(c.RasPublicKey) Handle(c.RasPublicKey)
}) })

View File

@@ -7,7 +7,7 @@ import (
mongoapp "mayfly-go/internal/mongo/application" mongoapp "mayfly-go/internal/mongo/application"
redisapp "mayfly-go/internal/redis/application" redisapp "mayfly-go/internal/redis/application"
tagapp "mayfly-go/internal/tag/application" tagapp "mayfly-go/internal/tag/application"
"mayfly-go/pkg/ctx" "mayfly-go/pkg/req"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@@ -24,7 +24,7 @@ func InitIndexRouter(router *gin.RouterGroup) {
{ {
// 首页基本信息统计 // 首页基本信息统计
index.GET("count", func(g *gin.Context) { index.GET("count", func(g *gin.Context) {
ctx.NewReqCtxWithGin(g). req.NewCtxWithGin(g).
Handle(i.Count) Handle(i.Count)
}) })
} }

View File

@@ -10,9 +10,9 @@ import (
sysapp "mayfly-go/internal/sys/application" sysapp "mayfly-go/internal/sys/application"
tagapp "mayfly-go/internal/tag/application" tagapp "mayfly-go/internal/tag/application"
"mayfly-go/pkg/biz" "mayfly-go/pkg/biz"
"mayfly-go/pkg/ctx"
"mayfly-go/pkg/ginx" "mayfly-go/pkg/ginx"
"mayfly-go/pkg/model" "mayfly-go/pkg/model"
"mayfly-go/pkg/req"
"mayfly-go/pkg/utils" "mayfly-go/pkg/utils"
"mayfly-go/pkg/ws" "mayfly-go/pkg/ws"
"strconv" "strconv"
@@ -33,7 +33,7 @@ type Db struct {
const DEFAULT_ROW_SIZE = 1800 const DEFAULT_ROW_SIZE = 1800
// @router /api/dbs [get] // @router /api/dbs [get]
func (d *Db) Dbs(rc *ctx.ReqCtx) { func (d *Db) Dbs(rc *req.Ctx) {
condition := new(entity.DbQuery) condition := new(entity.DbQuery)
condition.TagPathLike = rc.GinCtx.Query("tagPath") condition.TagPathLike = rc.GinCtx.Query("tagPath")
@@ -47,7 +47,7 @@ func (d *Db) Dbs(rc *ctx.ReqCtx) {
rc.ResData = d.DbApp.GetPageList(condition, ginx.GetPageParam(rc.GinCtx), new([]vo.SelectDataDbVO)) rc.ResData = d.DbApp.GetPageList(condition, ginx.GetPageParam(rc.GinCtx), new([]vo.SelectDataDbVO))
} }
func (d *Db) Save(rc *ctx.ReqCtx) { func (d *Db) Save(rc *req.Ctx) {
form := &form.DbForm{} form := &form.DbForm{}
ginx.BindJsonAndValid(rc.GinCtx, form) ginx.BindJsonAndValid(rc.GinCtx, form)
@@ -68,7 +68,7 @@ func (d *Db) Save(rc *ctx.ReqCtx) {
} }
// 获取数据库实例密码,由于数据库是加密存储,故提供该接口展示原文密码 // 获取数据库实例密码,由于数据库是加密存储,故提供该接口展示原文密码
func (d *Db) GetDbPwd(rc *ctx.ReqCtx) { func (d *Db) GetDbPwd(rc *req.Ctx) {
dbId := GetDbId(rc.GinCtx) dbId := GetDbId(rc.GinCtx)
dbEntity := d.DbApp.GetById(dbId, "Password") dbEntity := d.DbApp.GetById(dbId, "Password")
dbEntity.PwdDecrypt() dbEntity.PwdDecrypt()
@@ -76,7 +76,7 @@ func (d *Db) GetDbPwd(rc *ctx.ReqCtx) {
} }
// 获取数据库实例的所有数据库名 // 获取数据库实例的所有数据库名
func (d *Db) GetDatabaseNames(rc *ctx.ReqCtx) { func (d *Db) GetDatabaseNames(rc *req.Ctx) {
form := &form.DbForm{} form := &form.DbForm{}
ginx.BindJsonAndValid(rc.GinCtx, form) ginx.BindJsonAndValid(rc.GinCtx, form)
@@ -95,30 +95,30 @@ func (d *Db) GetDatabaseNames(rc *ctx.ReqCtx) {
rc.ResData = d.DbApp.GetDatabases(db) rc.ResData = d.DbApp.GetDatabases(db)
} }
func (d *Db) DeleteDb(rc *ctx.ReqCtx) { func (d *Db) DeleteDb(rc *req.Ctx) {
dbId := GetDbId(rc.GinCtx) dbId := GetDbId(rc.GinCtx)
d.DbApp.Delete(dbId) d.DbApp.Delete(dbId)
// 删除该库的sql执行记录 // 删除该库的sql执行记录
d.DbSqlExecApp.DeleteBy(&entity.DbSqlExec{DbId: dbId}) d.DbSqlExecApp.DeleteBy(&entity.DbSqlExec{DbId: dbId})
} }
func (d *Db) TableInfos(rc *ctx.ReqCtx) { func (d *Db) TableInfos(rc *req.Ctx) {
rc.ResData = d.DbApp.GetDbInstance(GetIdAndDb(rc.GinCtx)).GetMeta().GetTableInfos() rc.ResData = d.DbApp.GetDbInstance(GetIdAndDb(rc.GinCtx)).GetMeta().GetTableInfos()
} }
func (d *Db) TableIndex(rc *ctx.ReqCtx) { func (d *Db) TableIndex(rc *req.Ctx) {
tn := rc.GinCtx.Query("tableName") tn := rc.GinCtx.Query("tableName")
biz.NotEmpty(tn, "tableName不能为空") biz.NotEmpty(tn, "tableName不能为空")
rc.ResData = d.DbApp.GetDbInstance(GetIdAndDb(rc.GinCtx)).GetMeta().GetTableIndex(tn) rc.ResData = d.DbApp.GetDbInstance(GetIdAndDb(rc.GinCtx)).GetMeta().GetTableIndex(tn)
} }
func (d *Db) GetCreateTableDdl(rc *ctx.ReqCtx) { func (d *Db) GetCreateTableDdl(rc *req.Ctx) {
tn := rc.GinCtx.Query("tableName") tn := rc.GinCtx.Query("tableName")
biz.NotEmpty(tn, "tableName不能为空") biz.NotEmpty(tn, "tableName不能为空")
rc.ResData = d.DbApp.GetDbInstance(GetIdAndDb(rc.GinCtx)).GetMeta().GetCreateTableDdl(tn) rc.ResData = d.DbApp.GetDbInstance(GetIdAndDb(rc.GinCtx)).GetMeta().GetCreateTableDdl(tn)
} }
func (d *Db) ExecSql(rc *ctx.ReqCtx) { func (d *Db) ExecSql(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
form := &form.DbSqlExecForm{} form := &form.DbSqlExecForm{}
ginx.BindJsonAndValid(g, form) ginx.BindJsonAndValid(g, form)
@@ -171,7 +171,7 @@ func (d *Db) ExecSql(rc *ctx.ReqCtx) {
} }
// 执行sql文件 // 执行sql文件
func (d *Db) ExecSqlFile(rc *ctx.ReqCtx) { func (d *Db) ExecSqlFile(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
fileheader, err := g.FormFile("file") fileheader, err := g.FormFile("file")
biz.ErrIsNilAppendErr(err, "读取sql文件失败: %s") biz.ErrIsNilAppendErr(err, "读取sql文件失败: %s")
@@ -233,7 +233,7 @@ func (d *Db) ExecSqlFile(rc *ctx.ReqCtx) {
} }
// 数据库dump // 数据库dump
func (d *Db) DumpSql(rc *ctx.ReqCtx) { func (d *Db) DumpSql(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
dbId, db := GetIdAndDb(g) dbId, db := GetIdAndDb(g)
dumpType := g.Query("type") dumpType := g.Query("type")
@@ -315,13 +315,13 @@ func (d *Db) DumpSql(rc *ctx.ReqCtx) {
} }
// @router /api/db/:dbId/t-metadata [get] // @router /api/db/:dbId/t-metadata [get]
func (d *Db) TableMA(rc *ctx.ReqCtx) { func (d *Db) TableMA(rc *req.Ctx) {
dbi := d.DbApp.GetDbInstance(GetIdAndDb(rc.GinCtx)) dbi := d.DbApp.GetDbInstance(GetIdAndDb(rc.GinCtx))
rc.ResData = dbi.GetMeta().GetTables() rc.ResData = dbi.GetMeta().GetTables()
} }
// @router /api/db/:dbId/c-metadata [get] // @router /api/db/:dbId/c-metadata [get]
func (d *Db) ColumnMA(rc *ctx.ReqCtx) { func (d *Db) ColumnMA(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
tn := g.Query("tableName") tn := g.Query("tableName")
biz.NotEmpty(tn, "tableName不能为空") biz.NotEmpty(tn, "tableName不能为空")
@@ -331,7 +331,7 @@ func (d *Db) ColumnMA(rc *ctx.ReqCtx) {
} }
// @router /api/db/:dbId/hint-tables [get] // @router /api/db/:dbId/hint-tables [get]
func (d *Db) HintTables(rc *ctx.ReqCtx) { func (d *Db) HintTables(rc *req.Ctx) {
dbi := d.DbApp.GetDbInstance(GetIdAndDb(rc.GinCtx)) dbi := d.DbApp.GetDbInstance(GetIdAndDb(rc.GinCtx))
dm := dbi.GetMeta() dm := dbi.GetMeta()
@@ -371,7 +371,7 @@ func (d *Db) HintTables(rc *ctx.ReqCtx) {
} }
// @router /api/db/:dbId/sql [post] // @router /api/db/:dbId/sql [post]
func (d *Db) SaveSql(rc *ctx.ReqCtx) { func (d *Db) SaveSql(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
account := rc.LoginAccount account := rc.LoginAccount
dbSqlForm := &form.DbSqlSaveForm{} dbSqlForm := &form.DbSqlSaveForm{}
@@ -399,7 +399,7 @@ func (d *Db) SaveSql(rc *ctx.ReqCtx) {
} }
// 获取所有保存的sql names // 获取所有保存的sql names
func (d *Db) GetSqlNames(rc *ctx.ReqCtx) { func (d *Db) GetSqlNames(rc *req.Ctx) {
id, db := GetIdAndDb(rc.GinCtx) id, db := GetIdAndDb(rc.GinCtx)
// 获取用于是否有该dbsql的保存记录有则更改否则新增 // 获取用于是否有该dbsql的保存记录有则更改否则新增
dbSql := &entity.DbSql{Type: 1, DbId: id, Db: db} dbSql := &entity.DbSql{Type: 1, DbId: id, Db: db}
@@ -411,7 +411,7 @@ func (d *Db) GetSqlNames(rc *ctx.ReqCtx) {
} }
// 删除保存的sql // 删除保存的sql
func (d *Db) DeleteSql(rc *ctx.ReqCtx) { func (d *Db) DeleteSql(rc *req.Ctx) {
dbSql := &entity.DbSql{Type: 1, DbId: GetDbId(rc.GinCtx)} dbSql := &entity.DbSql{Type: 1, DbId: GetDbId(rc.GinCtx)}
dbSql.CreatorId = rc.LoginAccount.Id dbSql.CreatorId = rc.LoginAccount.Id
dbSql.Name = rc.GinCtx.Query("name") dbSql.Name = rc.GinCtx.Query("name")
@@ -421,7 +421,7 @@ func (d *Db) DeleteSql(rc *ctx.ReqCtx) {
} }
// @router /api/db/:dbId/sql [get] // @router /api/db/:dbId/sql [get]
func (d *Db) GetSql(rc *ctx.ReqCtx) { func (d *Db) GetSql(rc *req.Ctx) {
id, db := GetIdAndDb(rc.GinCtx) id, db := GetIdAndDb(rc.GinCtx)
// 根据创建者id 数据库id以及sql模板名称查询保存的sql信息 // 根据创建者id 数据库id以及sql模板名称查询保存的sql信息
dbSql := &entity.DbSql{Type: 1, DbId: id, Db: db} dbSql := &entity.DbSql{Type: 1, DbId: id, Db: db}

View File

@@ -3,15 +3,15 @@ package api
import ( import (
"mayfly-go/internal/db/application" "mayfly-go/internal/db/application"
"mayfly-go/internal/db/domain/entity" "mayfly-go/internal/db/domain/entity"
"mayfly-go/pkg/ctx"
"mayfly-go/pkg/ginx" "mayfly-go/pkg/ginx"
"mayfly-go/pkg/req"
) )
type DbSqlExec struct { type DbSqlExec struct {
DbSqlExecApp application.DbSqlExec DbSqlExecApp application.DbSqlExec
} }
func (d *DbSqlExec) DbSqlExecs(rc *ctx.ReqCtx) { func (d *DbSqlExec) DbSqlExecs(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
m := &entity.DbSqlExec{DbId: uint64(ginx.QueryInt(g, "dbId", 0)), m := &entity.DbSqlExec{DbId: uint64(ginx.QueryInt(g, "dbId", 0)),
Db: g.Query("db"), Db: g.Query("db"),

View File

@@ -5,7 +5,7 @@ import (
"mayfly-go/internal/db/application" "mayfly-go/internal/db/application"
sysapp "mayfly-go/internal/sys/application" sysapp "mayfly-go/internal/sys/application"
tagapp "mayfly-go/internal/tag/application" tagapp "mayfly-go/internal/tag/application"
"mayfly-go/pkg/ctx" "mayfly-go/pkg/req"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@@ -21,94 +21,94 @@ func InitDbRouter(router *gin.RouterGroup) {
} }
// 获取所有数据库列表 // 获取所有数据库列表
db.GET("", func(c *gin.Context) { db.GET("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(d.Dbs) req.NewCtxWithGin(c).Handle(d.Dbs)
}) })
saveDb := ctx.NewLogInfo("db-保存数据库信息").WithSave(true) saveDb := req.NewLogInfo("db-保存数据库信息").WithSave(true)
db.POST("", func(c *gin.Context) { db.POST("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c). req.NewCtxWithGin(c).
WithLog(saveDb). WithLog(saveDb).
Handle(d.Save) Handle(d.Save)
}) })
// 获取数据库实例的所有数据库名 // 获取数据库实例的所有数据库名
db.POST("databases", func(c *gin.Context) { db.POST("databases", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c). req.NewCtxWithGin(c).
Handle(d.GetDatabaseNames) Handle(d.GetDatabaseNames)
}) })
db.GET(":dbId/pwd", func(c *gin.Context) { db.GET(":dbId/pwd", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(d.GetDbPwd) req.NewCtxWithGin(c).Handle(d.GetDbPwd)
}) })
deleteDb := ctx.NewLogInfo("db-删除数据库信息").WithSave(true) deleteDb := req.NewLogInfo("db-删除数据库信息").WithSave(true)
db.DELETE(":dbId", func(c *gin.Context) { db.DELETE(":dbId", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c). req.NewCtxWithGin(c).
WithLog(deleteDb). WithLog(deleteDb).
Handle(d.DeleteDb) Handle(d.DeleteDb)
}) })
db.GET(":dbId/t-infos", func(c *gin.Context) { db.GET(":dbId/t-infos", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(d.TableInfos) req.NewCtxWithGin(c).Handle(d.TableInfos)
}) })
db.GET(":dbId/t-index", func(c *gin.Context) { db.GET(":dbId/t-index", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(d.TableIndex) req.NewCtxWithGin(c).Handle(d.TableIndex)
}) })
db.GET(":dbId/t-create-ddl", func(c *gin.Context) { db.GET(":dbId/t-create-ddl", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(d.GetCreateTableDdl) req.NewCtxWithGin(c).Handle(d.GetCreateTableDdl)
}) })
execSqlLog := ctx.NewLogInfo("db-执行Sql") execSqlLog := req.NewLogInfo("db-执行Sql")
db.POST(":dbId/exec-sql", func(g *gin.Context) { db.POST(":dbId/exec-sql", func(g *gin.Context) {
rc := ctx.NewReqCtxWithGin(g).WithLog(execSqlLog) rc := req.NewCtxWithGin(g).WithLog(execSqlLog)
rc.Handle(d.ExecSql) rc.Handle(d.ExecSql)
}) })
execSqlFileLog := ctx.NewLogInfo("db-执行Sql文件").WithSave(true) execSqlFileLog := req.NewLogInfo("db-执行Sql文件").WithSave(true)
db.POST(":dbId/exec-sql-file", func(g *gin.Context) { db.POST(":dbId/exec-sql-file", func(g *gin.Context) {
ctx.NewReqCtxWithGin(g). req.NewCtxWithGin(g).
WithLog(execSqlFileLog). WithLog(execSqlFileLog).
Handle(d.ExecSqlFile) Handle(d.ExecSqlFile)
}) })
dumpLog := ctx.NewLogInfo("db-导出sql文件").WithSave(true) dumpLog := req.NewLogInfo("db-导出sql文件").WithSave(true)
db.GET(":dbId/dump", func(g *gin.Context) { db.GET(":dbId/dump", func(g *gin.Context) {
ctx.NewReqCtxWithGin(g). req.NewCtxWithGin(g).
WithLog(dumpLog). WithLog(dumpLog).
Handle(d.DumpSql) Handle(d.DumpSql)
}) })
db.GET(":dbId/t-metadata", func(c *gin.Context) { db.GET(":dbId/t-metadata", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(d.TableMA) req.NewCtxWithGin(c).Handle(d.TableMA)
}) })
db.GET(":dbId/c-metadata", func(c *gin.Context) { db.GET(":dbId/c-metadata", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(d.ColumnMA) req.NewCtxWithGin(c).Handle(d.ColumnMA)
}) })
db.GET(":dbId/hint-tables", func(c *gin.Context) { db.GET(":dbId/hint-tables", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(d.HintTables) req.NewCtxWithGin(c).Handle(d.HintTables)
}) })
/** db sql相关接口 */ /** db sql相关接口 */
db.POST(":dbId/sql", func(c *gin.Context) { db.POST(":dbId/sql", func(c *gin.Context) {
rc := ctx.NewReqCtxWithGin(c) rc := req.NewCtxWithGin(c)
rc.Handle(d.SaveSql) rc.Handle(d.SaveSql)
}) })
db.GET(":dbId/sql", func(c *gin.Context) { db.GET(":dbId/sql", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(d.GetSql) req.NewCtxWithGin(c).Handle(d.GetSql)
}) })
db.DELETE(":dbId/sql", func(c *gin.Context) { db.DELETE(":dbId/sql", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(d.DeleteSql) req.NewCtxWithGin(c).Handle(d.DeleteSql)
}) })
db.GET(":dbId/sql-names", func(c *gin.Context) { db.GET(":dbId/sql-names", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(d.GetSqlNames) req.NewCtxWithGin(c).Handle(d.GetSqlNames)
}) })
} }
} }

View File

@@ -3,7 +3,7 @@ package router
import ( import (
"mayfly-go/internal/db/api" "mayfly-go/internal/db/api"
"mayfly-go/internal/db/application" "mayfly-go/internal/db/application"
"mayfly-go/pkg/ctx" "mayfly-go/pkg/req"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@@ -16,7 +16,7 @@ func InitDbSqlExecRouter(router *gin.RouterGroup) {
} }
// 获取所有数据库sql执行记录列表 // 获取所有数据库sql执行记录列表
db.GET("", func(c *gin.Context) { db.GET("", func(c *gin.Context) {
rc := ctx.NewReqCtxWithGin(c) rc := req.NewCtxWithGin(c)
rc.Handle(d.DbSqlExecs) rc.Handle(d.DbSqlExecs)
}) })
} }

View File

@@ -11,9 +11,9 @@ import (
tagapp "mayfly-go/internal/tag/application" tagapp "mayfly-go/internal/tag/application"
"mayfly-go/pkg/biz" "mayfly-go/pkg/biz"
"mayfly-go/pkg/config" "mayfly-go/pkg/config"
"mayfly-go/pkg/ctx"
"mayfly-go/pkg/ginx" "mayfly-go/pkg/ginx"
"mayfly-go/pkg/model" "mayfly-go/pkg/model"
"mayfly-go/pkg/req"
"mayfly-go/pkg/utils" "mayfly-go/pkg/utils"
"mayfly-go/pkg/ws" "mayfly-go/pkg/ws"
"os" "os"
@@ -31,7 +31,7 @@ type Machine struct {
TagApp tagapp.TagTree TagApp tagapp.TagTree
} }
func (m *Machine) Machines(rc *ctx.ReqCtx) { func (m *Machine) Machines(rc *req.Ctx) {
condition := new(entity.MachineQuery) condition := new(entity.MachineQuery)
condition.Ip = rc.GinCtx.Query("ip") condition.Ip = rc.GinCtx.Query("ip")
condition.Name = rc.GinCtx.Query("name") condition.Name = rc.GinCtx.Query("name")
@@ -58,12 +58,12 @@ func (m *Machine) Machines(rc *ctx.ReqCtx) {
rc.ResData = res rc.ResData = res
} }
func (m *Machine) MachineStats(rc *ctx.ReqCtx) { func (m *Machine) MachineStats(rc *req.Ctx) {
stats := m.MachineApp.GetCli(GetMachineId(rc.GinCtx)).GetAllStats() stats := m.MachineApp.GetCli(GetMachineId(rc.GinCtx)).GetAllStats()
rc.ResData = stats rc.ResData = stats
} }
func (m *Machine) SaveMachine(rc *ctx.ReqCtx) { func (m *Machine) SaveMachine(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
machineForm := new(form.MachineForm) machineForm := new(form.MachineForm)
ginx.BindJsonAndValid(g, machineForm) ginx.BindJsonAndValid(g, machineForm)
@@ -87,14 +87,14 @@ func (m *Machine) SaveMachine(rc *ctx.ReqCtx) {
} }
// 获取机器实例密码,由于数据库是加密存储,故提供该接口展示原文密码 // 获取机器实例密码,由于数据库是加密存储,故提供该接口展示原文密码
func (m *Machine) GetMachinePwd(rc *ctx.ReqCtx) { func (m *Machine) GetMachinePwd(rc *req.Ctx) {
mid := GetMachineId(rc.GinCtx) mid := GetMachineId(rc.GinCtx)
me := m.MachineApp.GetById(mid, "Password") me := m.MachineApp.GetById(mid, "Password")
me.PwdDecrypt() me.PwdDecrypt()
rc.ResData = me.Password rc.ResData = me.Password
} }
func (m *Machine) ChangeStatus(rc *ctx.ReqCtx) { func (m *Machine) ChangeStatus(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
id := uint64(ginx.PathParamInt(g, "machineId")) id := uint64(ginx.PathParamInt(g, "machineId"))
status := int8(ginx.PathParamInt(g, "status")) status := int8(ginx.PathParamInt(g, "status"))
@@ -102,19 +102,19 @@ func (m *Machine) ChangeStatus(rc *ctx.ReqCtx) {
m.MachineApp.ChangeStatus(id, status) m.MachineApp.ChangeStatus(id, status)
} }
func (m *Machine) DeleteMachine(rc *ctx.ReqCtx) { func (m *Machine) DeleteMachine(rc *req.Ctx) {
id := uint64(ginx.PathParamInt(rc.GinCtx, "machineId")) id := uint64(ginx.PathParamInt(rc.GinCtx, "machineId"))
rc.ReqParam = id rc.ReqParam = id
m.MachineApp.Delete(id) m.MachineApp.Delete(id)
} }
// 关闭机器客户端 // 关闭机器客户端
func (m *Machine) CloseCli(rc *ctx.ReqCtx) { func (m *Machine) CloseCli(rc *req.Ctx) {
machine.DeleteCli(GetMachineId(rc.GinCtx)) machine.DeleteCli(GetMachineId(rc.GinCtx))
} }
// 获取进程列表信息 // 获取进程列表信息
func (m *Machine) GetProcess(rc *ctx.ReqCtx) { func (m *Machine) GetProcess(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
cmd := "ps -aux " cmd := "ps -aux "
sortType := g.Query("sortType") sortType := g.Query("sortType")
@@ -145,7 +145,7 @@ func (m *Machine) GetProcess(rc *ctx.ReqCtx) {
} }
// 终止进程 // 终止进程
func (m *Machine) KillProcess(rc *ctx.ReqCtx) { func (m *Machine) KillProcess(rc *req.Ctx) {
pid := rc.GinCtx.Query("pid") pid := rc.GinCtx.Query("pid")
biz.NotEmpty(pid, "进程id不能为空") biz.NotEmpty(pid, "进程id不能为空")
@@ -169,8 +169,8 @@ func (m *Machine) WsSSH(g *gin.Context) {
biz.ErrIsNilAppendErr(err, "升级websocket失败: %s") biz.ErrIsNilAppendErr(err, "升级websocket失败: %s")
// 权限校验 // 权限校验
rc := ctx.NewReqCtxWithGin(g).WithRequiredPermission(ctx.NewPermission("machine:terminal")) rc := req.NewCtxWithGin(g).WithRequiredPermission(req.NewPermission("machine:terminal"))
if err = ctx.PermissionHandler(rc); err != nil { if err = req.PermissionHandler(rc); err != nil {
panic(biz.NewBizErr("\033[1;31m您没有权限操作该机器终端,请重新登录后再试~\033[0m")) panic(biz.NewBizErr("\033[1;31m您没有权限操作该机器终端,请重新登录后再试~\033[0m"))
} }
@@ -197,16 +197,16 @@ func (m *Machine) WsSSH(g *gin.Context) {
biz.ErrIsNilAppendErr(err, "\033[1;31m连接失败: %s\033[0m") biz.ErrIsNilAppendErr(err, "\033[1;31m连接失败: %s\033[0m")
// 记录系统操作日志 // 记录系统操作日志
rc.WithLog(ctx.NewLogInfo("机器-终端操作").WithSave(true)) rc.WithLog(req.NewLogInfo("机器-终端操作").WithSave(true))
rc.ReqParam = cli.GetMachine().GetLogDesc() rc.ReqParam = cli.GetMachine().GetLogDesc()
ctx.LogHandler(rc) req.LogHandler(rc)
mts.Start() mts.Start()
defer mts.Stop() defer mts.Stop()
} }
// 获取机器终端回放记录的相应文件夹名或文件内容 // 获取机器终端回放记录的相应文件夹名或文件内容
func (m *Machine) MachineRecDirNames(rc *ctx.ReqCtx) { func (m *Machine) MachineRecDirNames(rc *req.Ctx) {
readPath := rc.GinCtx.Query("path") readPath := rc.GinCtx.Query("path")
biz.NotEmpty(readPath, "path不能为空") biz.NotEmpty(readPath, "path不能为空")
path_ := path.Join(config.Conf.Server.GetMachineRecPath(), readPath) path_ := path.Join(config.Conf.Server.GetMachineRecPath(), readPath)

View File

@@ -10,8 +10,8 @@ import (
"mayfly-go/internal/machine/domain/entity" "mayfly-go/internal/machine/domain/entity"
sysApplication "mayfly-go/internal/sys/application" sysApplication "mayfly-go/internal/sys/application"
"mayfly-go/pkg/biz" "mayfly-go/pkg/biz"
"mayfly-go/pkg/ctx"
"mayfly-go/pkg/ginx" "mayfly-go/pkg/ginx"
"mayfly-go/pkg/req"
"mayfly-go/pkg/utils" "mayfly-go/pkg/utils"
"mayfly-go/pkg/ws" "mayfly-go/pkg/ws"
"sort" "sort"
@@ -33,13 +33,13 @@ const (
max_read_size = 1 * 1024 * 1024 max_read_size = 1 * 1024 * 1024
) )
func (m *MachineFile) MachineFiles(rc *ctx.ReqCtx) { func (m *MachineFile) MachineFiles(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
condition := &entity.MachineFile{MachineId: GetMachineId(g)} condition := &entity.MachineFile{MachineId: GetMachineId(g)}
rc.ResData = m.MachineFileApp.GetPageList(condition, ginx.GetPageParam(g), new([]vo.MachineFileVO)) rc.ResData = m.MachineFileApp.GetPageList(condition, ginx.GetPageParam(g), new([]vo.MachineFileVO))
} }
func (m *MachineFile) SaveMachineFiles(rc *ctx.ReqCtx) { func (m *MachineFile) SaveMachineFiles(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
fileForm := new(form.MachineFileForm) fileForm := new(form.MachineFileForm)
ginx.BindJsonAndValid(g, fileForm) ginx.BindJsonAndValid(g, fileForm)
@@ -52,7 +52,7 @@ func (m *MachineFile) SaveMachineFiles(rc *ctx.ReqCtx) {
m.MachineFileApp.Save(entity) m.MachineFileApp.Save(entity)
} }
func (m *MachineFile) DeleteFile(rc *ctx.ReqCtx) { func (m *MachineFile) DeleteFile(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
fid := GetMachineFileId(g) fid := GetMachineFileId(g)
m.MachineFileApp.Delete(fid) m.MachineFileApp.Delete(fid)
@@ -60,7 +60,7 @@ func (m *MachineFile) DeleteFile(rc *ctx.ReqCtx) {
/*** sftp相关操作 */ /*** sftp相关操作 */
func (m *MachineFile) CreateFile(rc *ctx.ReqCtx) { func (m *MachineFile) CreateFile(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
fid := GetMachineFileId(g) fid := GetMachineFileId(g)
@@ -79,7 +79,7 @@ func (m *MachineFile) CreateFile(rc *ctx.ReqCtx) {
} }
func (m *MachineFile) ReadFileContent(rc *ctx.ReqCtx) { func (m *MachineFile) ReadFileContent(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
fid := GetMachineFileId(g) fid := GetMachineFileId(g)
readPath := g.Query("path") readPath := g.Query("path")
@@ -109,7 +109,7 @@ func (m *MachineFile) ReadFileContent(rc *ctx.ReqCtx) {
} }
} }
func (m *MachineFile) GetDirEntry(rc *ctx.ReqCtx) { func (m *MachineFile) GetDirEntry(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
fid := GetMachineFileId(g) fid := GetMachineFileId(g)
readPath := g.Query("path") readPath := g.Query("path")
@@ -134,7 +134,7 @@ func (m *MachineFile) GetDirEntry(rc *ctx.ReqCtx) {
rc.ReqParam = fmt.Sprintf("path: %s", readPath) rc.ReqParam = fmt.Sprintf("path: %s", readPath)
} }
func (m *MachineFile) WriteFileContent(rc *ctx.ReqCtx) { func (m *MachineFile) WriteFileContent(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
fid := GetMachineFileId(g) fid := GetMachineFileId(g)
@@ -148,7 +148,7 @@ func (m *MachineFile) WriteFileContent(rc *ctx.ReqCtx) {
rc.ReqParam = fmt.Sprintf("%s -> 修改文件内容: %s", mi.GetLogDesc(), path) rc.ReqParam = fmt.Sprintf("%s -> 修改文件内容: %s", mi.GetLogDesc(), path)
} }
func (m *MachineFile) UploadFile(rc *ctx.ReqCtx) { func (m *MachineFile) UploadFile(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
fid := GetMachineFileId(g) fid := GetMachineFileId(g)
path := g.PostForm("path") path := g.PostForm("path")
@@ -179,7 +179,7 @@ func (m *MachineFile) UploadFile(rc *ctx.ReqCtx) {
}() }()
} }
func (m *MachineFile) RemoveFile(rc *ctx.ReqCtx) { func (m *MachineFile) RemoveFile(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
fid := GetMachineFileId(g) fid := GetMachineFileId(g)
path := g.Query("path") path := g.Query("path")

View File

@@ -8,8 +8,8 @@ import (
"mayfly-go/internal/machine/domain/entity" "mayfly-go/internal/machine/domain/entity"
tagapp "mayfly-go/internal/tag/application" tagapp "mayfly-go/internal/tag/application"
"mayfly-go/pkg/biz" "mayfly-go/pkg/biz"
"mayfly-go/pkg/ctx"
"mayfly-go/pkg/ginx" "mayfly-go/pkg/ginx"
"mayfly-go/pkg/req"
"mayfly-go/pkg/utils" "mayfly-go/pkg/utils"
"strconv" "strconv"
@@ -22,13 +22,13 @@ type MachineScript struct {
TagApp tagapp.TagTree TagApp tagapp.TagTree
} }
func (m *MachineScript) MachineScripts(rc *ctx.ReqCtx) { func (m *MachineScript) MachineScripts(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
condition := &entity.MachineScript{MachineId: GetMachineId(g)} condition := &entity.MachineScript{MachineId: GetMachineId(g)}
rc.ResData = m.MachineScriptApp.GetPageList(condition, ginx.GetPageParam(g), new([]vo.MachineScriptVO)) rc.ResData = m.MachineScriptApp.GetPageList(condition, ginx.GetPageParam(g), new([]vo.MachineScriptVO))
} }
func (m *MachineScript) SaveMachineScript(rc *ctx.ReqCtx) { func (m *MachineScript) SaveMachineScript(rc *req.Ctx) {
form := new(form.MachineScriptForm) form := new(form.MachineScriptForm)
ginx.BindJsonAndValid(rc.GinCtx, form) ginx.BindJsonAndValid(rc.GinCtx, form)
rc.ReqParam = form rc.ReqParam = form
@@ -41,7 +41,7 @@ func (m *MachineScript) SaveMachineScript(rc *ctx.ReqCtx) {
m.MachineScriptApp.Save(machineScript) m.MachineScriptApp.Save(machineScript)
} }
func (m *MachineScript) DeleteMachineScript(rc *ctx.ReqCtx) { func (m *MachineScript) DeleteMachineScript(rc *req.Ctx) {
msa := m.MachineScriptApp msa := m.MachineScriptApp
sid := GetMachineScriptId(rc.GinCtx) sid := GetMachineScriptId(rc.GinCtx)
ms := msa.GetById(sid) ms := msa.GetById(sid)
@@ -50,7 +50,7 @@ func (m *MachineScript) DeleteMachineScript(rc *ctx.ReqCtx) {
msa.Delete(sid) msa.Delete(sid)
} }
func (m *MachineScript) RunMachineScript(rc *ctx.ReqCtx) { func (m *MachineScript) RunMachineScript(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
scriptId := GetMachineScriptId(g) scriptId := GetMachineScriptId(g)

View File

@@ -92,19 +92,18 @@ func (c *Cli) GetSession() (*ssh.Session, error) {
// 执行shell // 执行shell
// @param shell shell脚本命令 // @param shell shell脚本命令
func (c *Cli) Run(shell string) (*string, error) { func (c *Cli) Run(shell string) (string, error) {
session, err := c.GetSession() session, err := c.GetSession()
if err != nil { if err != nil {
c.Close() c.Close()
return nil, err return "", err
} }
defer session.Close() defer session.Close()
buf, rerr := session.CombinedOutput(shell) buf, err := session.CombinedOutput(shell)
if rerr != nil { if err != nil {
return nil, rerr return "", err
} }
res := string(buf) return string(buf), nil
return &res, nil
} }
func (c *Cli) GetMachine() *entity.Machine { func (c *Cli) GetMachine() *entity.Machine {

View File

@@ -73,7 +73,7 @@ top -b -n 1 | grep Cpu
func (c *Cli) GetAllStats() *Stats { func (c *Cli) GetAllStats() *Stats {
res, _ := c.Run(StatsShell) res, _ := c.Run(StatsShell)
infos := strings.Split(*res, "-----") infos := strings.Split(res, "-----")
stats := new(Stats) stats := new(Stats)
getUptime(infos[0], stats) getUptime(infos[0], stats)
getHostname(infos[1], stats) getHostname(infos[1], stats)

View File

@@ -4,7 +4,7 @@ import (
"mayfly-go/internal/machine/api" "mayfly-go/internal/machine/api"
"mayfly-go/internal/machine/application" "mayfly-go/internal/machine/application"
tagapp "mayfly-go/internal/tag/application" tagapp "mayfly-go/internal/tag/application"
"mayfly-go/pkg/ctx" "mayfly-go/pkg/req"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@@ -18,64 +18,64 @@ func InitMachineRouter(router *gin.RouterGroup) {
machines := router.Group("machines") machines := router.Group("machines")
{ {
machines.GET("", func(c *gin.Context) { machines.GET("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(m.Machines) req.NewCtxWithGin(c).Handle(m.Machines)
}) })
machines.GET(":machineId/pwd", func(c *gin.Context) { machines.GET(":machineId/pwd", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(m.GetMachinePwd) req.NewCtxWithGin(c).Handle(m.GetMachinePwd)
}) })
machines.GET(":machineId/stats", func(c *gin.Context) { machines.GET(":machineId/stats", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(m.MachineStats) req.NewCtxWithGin(c).Handle(m.MachineStats)
}) })
machines.GET(":machineId/process", func(c *gin.Context) { machines.GET(":machineId/process", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(m.GetProcess) req.NewCtxWithGin(c).Handle(m.GetProcess)
}) })
// 终止进程 // 终止进程
killProcessL := ctx.NewLogInfo("终止进程").WithSave(true) killProcessL := req.NewLogInfo("终止进程").WithSave(true)
killProcessP := ctx.NewPermission("machine:killprocess") killProcessP := req.NewPermission("machine:killprocess")
machines.DELETE(":machineId/process", func(c *gin.Context) { machines.DELETE(":machineId/process", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c). req.NewCtxWithGin(c).
WithLog(killProcessL). WithLog(killProcessL).
WithRequiredPermission(killProcessP). WithRequiredPermission(killProcessP).
Handle(m.KillProcess) Handle(m.KillProcess)
}) })
saveMachine := ctx.NewLogInfo("保存机器信息").WithSave(true) saveMachine := req.NewLogInfo("保存机器信息").WithSave(true)
saveMachineP := ctx.NewPermission("machine:update") saveMachineP := req.NewPermission("machine:update")
machines.POST("", func(c *gin.Context) { machines.POST("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c). req.NewCtxWithGin(c).
WithLog(saveMachine). WithLog(saveMachine).
WithRequiredPermission(saveMachineP). WithRequiredPermission(saveMachineP).
Handle(m.SaveMachine) Handle(m.SaveMachine)
}) })
changeStatus := ctx.NewLogInfo("调整机器状态").WithSave(true) changeStatus := req.NewLogInfo("调整机器状态").WithSave(true)
machines.PUT(":machineId/:status", func(c *gin.Context) { machines.PUT(":machineId/:status", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c). req.NewCtxWithGin(c).
WithLog(changeStatus). WithLog(changeStatus).
Handle(m.ChangeStatus) Handle(m.ChangeStatus)
}) })
delMachine := ctx.NewLogInfo("删除机器").WithSave(true) delMachine := req.NewLogInfo("删除机器").WithSave(true)
machines.DELETE(":machineId", func(c *gin.Context) { machines.DELETE(":machineId", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c). req.NewCtxWithGin(c).
WithLog(delMachine). WithLog(delMachine).
Handle(m.DeleteMachine) Handle(m.DeleteMachine)
}) })
closeCli := ctx.NewLogInfo("关闭机器客户端").WithSave(true) closeCli := req.NewLogInfo("关闭机器客户端").WithSave(true)
machines.DELETE(":machineId/close-cli", func(c *gin.Context) { machines.DELETE(":machineId/close-cli", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(closeCli).Handle(m.CloseCli) req.NewCtxWithGin(c).WithLog(closeCli).Handle(m.CloseCli)
}) })
machines.GET(":machineId/terminal", m.WsSSH) machines.GET(":machineId/terminal", m.WsSSH)
// 获取机器终端回放记录的相应文件夹名或文件名,目前具有保存机器信息的权限标识才有权限查看终端回放 // 获取机器终端回放记录的相应文件夹名或文件名,目前具有保存机器信息的权限标识才有权限查看终端回放
machines.GET("rec/names", func(c *gin.Context) { machines.GET("rec/names", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c). req.NewCtxWithGin(c).
WithRequiredPermission(saveMachineP). WithRequiredPermission(saveMachineP).
Handle(m.MachineRecDirNames) Handle(m.MachineRecDirNames)
}) })

View File

@@ -4,7 +4,7 @@ import (
"mayfly-go/internal/machine/api" "mayfly-go/internal/machine/api"
"mayfly-go/internal/machine/application" "mayfly-go/internal/machine/application"
sysApplication "mayfly-go/internal/sys/application" sysApplication "mayfly-go/internal/sys/application"
"mayfly-go/pkg/ctx" "mayfly-go/pkg/req"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@@ -19,66 +19,66 @@ func InitMachineFileRouter(router *gin.RouterGroup) {
// 获取指定机器文件列表 // 获取指定机器文件列表
machineFile.GET(":machineId/files", func(c *gin.Context) { machineFile.GET(":machineId/files", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(mf.MachineFiles) req.NewCtxWithGin(c).Handle(mf.MachineFiles)
}) })
// 新增修改机器文件 // 新增修改机器文件
addFileConf := ctx.NewLogInfo("机器-新增文件配置").WithSave(true) addFileConf := req.NewLogInfo("机器-新增文件配置").WithSave(true)
afcP := ctx.NewPermission("machine:file:add") afcP := req.NewPermission("machine:file:add")
machineFile.POST(":machineId/files", func(c *gin.Context) { machineFile.POST(":machineId/files", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(addFileConf). req.NewCtxWithGin(c).WithLog(addFileConf).
WithRequiredPermission(afcP). WithRequiredPermission(afcP).
Handle(mf.SaveMachineFiles) Handle(mf.SaveMachineFiles)
}) })
// 删除机器文件 // 删除机器文件
delFileConf := ctx.NewLogInfo("机器-删除文件配置").WithSave(true) delFileConf := req.NewLogInfo("机器-删除文件配置").WithSave(true)
dfcP := ctx.NewPermission("machine:file:del") dfcP := req.NewPermission("machine:file:del")
machineFile.DELETE(":machineId/files/:fileId", func(c *gin.Context) { machineFile.DELETE(":machineId/files/:fileId", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(delFileConf). req.NewCtxWithGin(c).WithLog(delFileConf).
WithRequiredPermission(dfcP). WithRequiredPermission(dfcP).
Handle(mf.DeleteFile) Handle(mf.DeleteFile)
}) })
getContent := ctx.NewLogInfo("机器-获取文件内容").WithSave(true) getContent := req.NewLogInfo("机器-获取文件内容").WithSave(true)
machineFile.GET(":machineId/files/:fileId/read", func(c *gin.Context) { machineFile.GET(":machineId/files/:fileId/read", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(getContent). req.NewCtxWithGin(c).WithLog(getContent).
Handle(mf.ReadFileContent) Handle(mf.ReadFileContent)
}) })
getDir := ctx.NewLogInfo("机器-获取目录") getDir := req.NewLogInfo("机器-获取目录")
machineFile.GET(":machineId/files/:fileId/read-dir", func(c *gin.Context) { machineFile.GET(":machineId/files/:fileId/read-dir", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(getDir). req.NewCtxWithGin(c).WithLog(getDir).
Handle(mf.GetDirEntry) Handle(mf.GetDirEntry)
}) })
writeFile := ctx.NewLogInfo("机器-修改文件内容").WithSave(true) writeFile := req.NewLogInfo("机器-修改文件内容").WithSave(true)
wfP := ctx.NewPermission("machine:file:write") wfP := req.NewPermission("machine:file:write")
machineFile.POST(":machineId/files/:fileId/write", func(c *gin.Context) { machineFile.POST(":machineId/files/:fileId/write", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(writeFile). req.NewCtxWithGin(c).WithLog(writeFile).
WithRequiredPermission(wfP). WithRequiredPermission(wfP).
Handle(mf.WriteFileContent) Handle(mf.WriteFileContent)
}) })
createFile := ctx.NewLogInfo("机器-创建文件or目录").WithSave(true) createFile := req.NewLogInfo("机器-创建文件or目录").WithSave(true)
machineFile.POST(":machineId/files/:fileId/create-file", func(c *gin.Context) { machineFile.POST(":machineId/files/:fileId/create-file", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(createFile). req.NewCtxWithGin(c).WithLog(createFile).
WithRequiredPermission(wfP). WithRequiredPermission(wfP).
Handle(mf.CreateFile) Handle(mf.CreateFile)
}) })
uploadFile := ctx.NewLogInfo("机器-文件上传").WithSave(true) uploadFile := req.NewLogInfo("机器-文件上传").WithSave(true)
ufP := ctx.NewPermission("machine:file:upload") ufP := req.NewPermission("machine:file:upload")
machineFile.POST(":machineId/files/:fileId/upload", func(c *gin.Context) { machineFile.POST(":machineId/files/:fileId/upload", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(uploadFile). req.NewCtxWithGin(c).WithLog(uploadFile).
WithRequiredPermission(ufP). WithRequiredPermission(ufP).
Handle(mf.UploadFile) Handle(mf.UploadFile)
}) })
removeFile := ctx.NewLogInfo("机器-删除文件or文件夹").WithSave(true) removeFile := req.NewLogInfo("机器-删除文件or文件夹").WithSave(true)
rfP := ctx.NewPermission("machine:file:rm") rfP := req.NewPermission("machine:file:rm")
machineFile.DELETE(":machineId/files/:fileId/remove", func(c *gin.Context) { machineFile.DELETE(":machineId/files/:fileId/remove", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(removeFile). req.NewCtxWithGin(c).WithLog(removeFile).
WithRequiredPermission(rfP). WithRequiredPermission(rfP).
Handle(mf.RemoveFile) Handle(mf.RemoveFile)
}) })

View File

@@ -4,7 +4,7 @@ import (
"mayfly-go/internal/machine/api" "mayfly-go/internal/machine/api"
"mayfly-go/internal/machine/application" "mayfly-go/internal/machine/application"
tagapp "mayfly-go/internal/tag/application" tagapp "mayfly-go/internal/tag/application"
"mayfly-go/pkg/ctx" "mayfly-go/pkg/req"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@@ -20,32 +20,32 @@ func InitMachineScriptRouter(router *gin.RouterGroup) {
// 获取指定机器脚本列表 // 获取指定机器脚本列表
machines.GET(":machineId/scripts", func(c *gin.Context) { machines.GET(":machineId/scripts", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(ms.MachineScripts) req.NewCtxWithGin(c).Handle(ms.MachineScripts)
}) })
saveMachienScriptLog := ctx.NewLogInfo("机器-保存脚本").WithSave(true) saveMachienScriptLog := req.NewLogInfo("机器-保存脚本").WithSave(true)
smsP := ctx.NewPermission("machine:script:save") smsP := req.NewPermission("machine:script:save")
// 保存脚本 // 保存脚本
machines.POST(":machineId/scripts", func(c *gin.Context) { machines.POST(":machineId/scripts", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(saveMachienScriptLog). req.NewCtxWithGin(c).WithLog(saveMachienScriptLog).
WithRequiredPermission(smsP). WithRequiredPermission(smsP).
Handle(ms.SaveMachineScript) Handle(ms.SaveMachineScript)
}) })
deleteLog := ctx.NewLogInfo("机器-删除脚本").WithSave(true) deleteLog := req.NewLogInfo("机器-删除脚本").WithSave(true)
dP := ctx.NewPermission("machine:script:del") dP := req.NewPermission("machine:script:del")
// 保存脚本 // 保存脚本
machines.DELETE(":machineId/scripts/:scriptId", func(c *gin.Context) { machines.DELETE(":machineId/scripts/:scriptId", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(deleteLog). req.NewCtxWithGin(c).WithLog(deleteLog).
WithRequiredPermission(dP). WithRequiredPermission(dP).
Handle(ms.DeleteMachineScript) Handle(ms.DeleteMachineScript)
}) })
runLog := ctx.NewLogInfo("机器-执行脚本").WithSave(true) runLog := req.NewLogInfo("机器-执行脚本").WithSave(true)
rP := ctx.NewPermission("machine:script:run") rP := req.NewPermission("machine:script:run")
// 运行脚本 // 运行脚本
machines.GET(":machineId/scripts/:scriptId/run", func(c *gin.Context) { machines.GET(":machineId/scripts/:scriptId/run", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(runLog). req.NewCtxWithGin(c).WithLog(runLog).
WithRequiredPermission(rP). WithRequiredPermission(rP).
Handle(ms.RunMachineScript) Handle(ms.RunMachineScript)
}) })

View File

@@ -7,9 +7,9 @@ import (
"mayfly-go/internal/mongo/domain/entity" "mayfly-go/internal/mongo/domain/entity"
tagapp "mayfly-go/internal/tag/application" tagapp "mayfly-go/internal/tag/application"
"mayfly-go/pkg/biz" "mayfly-go/pkg/biz"
"mayfly-go/pkg/ctx"
"mayfly-go/pkg/ginx" "mayfly-go/pkg/ginx"
"mayfly-go/pkg/model" "mayfly-go/pkg/model"
"mayfly-go/pkg/req"
"mayfly-go/pkg/utils" "mayfly-go/pkg/utils"
"regexp" "regexp"
"strconv" "strconv"
@@ -25,7 +25,7 @@ type Mongo struct {
TagApp tagapp.TagTree TagApp tagapp.TagTree
} }
func (m *Mongo) Mongos(rc *ctx.ReqCtx) { func (m *Mongo) Mongos(rc *req.Ctx) {
condition := new(entity.MongoQuery) condition := new(entity.MongoQuery)
condition.TagPathLike = rc.GinCtx.Query("tagPath") condition.TagPathLike = rc.GinCtx.Query("tagPath")
@@ -39,7 +39,7 @@ func (m *Mongo) Mongos(rc *ctx.ReqCtx) {
rc.ResData = m.MongoApp.GetPageList(condition, ginx.GetPageParam(rc.GinCtx), new([]entity.Mongo)) rc.ResData = m.MongoApp.GetPageList(condition, ginx.GetPageParam(rc.GinCtx), new([]entity.Mongo))
} }
func (m *Mongo) Save(rc *ctx.ReqCtx) { func (m *Mongo) Save(rc *req.Ctx) {
form := &form.Mongo{} form := &form.Mongo{}
ginx.BindJsonAndValid(rc.GinCtx, form) ginx.BindJsonAndValid(rc.GinCtx, form)
@@ -57,18 +57,18 @@ func (m *Mongo) Save(rc *ctx.ReqCtx) {
m.MongoApp.Save(mongo) m.MongoApp.Save(mongo)
} }
func (m *Mongo) DeleteMongo(rc *ctx.ReqCtx) { func (m *Mongo) DeleteMongo(rc *req.Ctx) {
m.MongoApp.Delete(m.GetMongoId(rc.GinCtx)) m.MongoApp.Delete(m.GetMongoId(rc.GinCtx))
} }
func (m *Mongo) Databases(rc *ctx.ReqCtx) { func (m *Mongo) Databases(rc *req.Ctx) {
cli := m.MongoApp.GetMongoCli(m.GetMongoId(rc.GinCtx)) cli := m.MongoApp.GetMongoCli(m.GetMongoId(rc.GinCtx))
res, err := cli.ListDatabases(context.TODO(), bson.D{}) res, err := cli.ListDatabases(context.TODO(), bson.D{})
biz.ErrIsNilAppendErr(err, "获取mongo所有库信息失败: %s") biz.ErrIsNilAppendErr(err, "获取mongo所有库信息失败: %s")
rc.ResData = res rc.ResData = res
} }
func (m *Mongo) Collections(rc *ctx.ReqCtx) { func (m *Mongo) Collections(rc *req.Ctx) {
cli := m.MongoApp.GetMongoCli(m.GetMongoId(rc.GinCtx)) cli := m.MongoApp.GetMongoCli(m.GetMongoId(rc.GinCtx))
db := rc.GinCtx.Query("database") db := rc.GinCtx.Query("database")
biz.NotEmpty(db, "database不能为空") biz.NotEmpty(db, "database不能为空")
@@ -78,7 +78,7 @@ func (m *Mongo) Collections(rc *ctx.ReqCtx) {
rc.ResData = res rc.ResData = res
} }
func (m *Mongo) RunCommand(rc *ctx.ReqCtx) { func (m *Mongo) RunCommand(rc *req.Ctx) {
commandForm := new(form.MongoRunCommand) commandForm := new(form.MongoRunCommand)
ginx.BindJsonAndValid(rc.GinCtx, commandForm) ginx.BindJsonAndValid(rc.GinCtx, commandForm)
cli := m.MongoApp.GetMongoCli(m.GetMongoId(rc.GinCtx)) cli := m.MongoApp.GetMongoCli(m.GetMongoId(rc.GinCtx))
@@ -94,7 +94,7 @@ func (m *Mongo) RunCommand(rc *ctx.ReqCtx) {
rc.ResData = bm rc.ResData = bm
} }
func (m *Mongo) FindCommand(rc *ctx.ReqCtx) { func (m *Mongo) FindCommand(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
cli := m.MongoApp.GetMongoCli(m.GetMongoId(g)) cli := m.MongoApp.GetMongoCli(m.GetMongoId(g))
commandForm := new(form.MongoFindCommand) commandForm := new(form.MongoFindCommand)
@@ -127,7 +127,7 @@ func (m *Mongo) FindCommand(rc *ctx.ReqCtx) {
rc.ResData = res rc.ResData = res
} }
func (m *Mongo) UpdateByIdCommand(rc *ctx.ReqCtx) { func (m *Mongo) UpdateByIdCommand(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
cli := m.MongoApp.GetMongoCli(m.GetMongoId(g)) cli := m.MongoApp.GetMongoCli(m.GetMongoId(g))
commandForm := new(form.MongoUpdateByIdCommand) commandForm := new(form.MongoUpdateByIdCommand)
@@ -150,7 +150,7 @@ func (m *Mongo) UpdateByIdCommand(rc *ctx.ReqCtx) {
rc.ResData = res rc.ResData = res
} }
func (m *Mongo) DeleteByIdCommand(rc *ctx.ReqCtx) { func (m *Mongo) DeleteByIdCommand(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
cli := m.MongoApp.GetMongoCli(m.GetMongoId(g)) cli := m.MongoApp.GetMongoCli(m.GetMongoId(g))
commandForm := new(form.MongoUpdateByIdCommand) commandForm := new(form.MongoUpdateByIdCommand)
@@ -173,7 +173,7 @@ func (m *Mongo) DeleteByIdCommand(rc *ctx.ReqCtx) {
rc.ResData = res rc.ResData = res
} }
func (m *Mongo) InsertOneCommand(rc *ctx.ReqCtx) { func (m *Mongo) InsertOneCommand(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
cli := m.MongoApp.GetMongoCli(m.GetMongoId(g)) cli := m.MongoApp.GetMongoCli(m.GetMongoId(g))
commandForm := new(form.MongoInsertCommand) commandForm := new(form.MongoInsertCommand)

View File

@@ -4,7 +4,7 @@ import (
"mayfly-go/internal/mongo/api" "mayfly-go/internal/mongo/api"
"mayfly-go/internal/mongo/application" "mayfly-go/internal/mongo/application"
tagapp "mayfly-go/internal/tag/application" tagapp "mayfly-go/internal/tag/application"
"mayfly-go/pkg/ctx" "mayfly-go/pkg/req"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@@ -19,68 +19,68 @@ func InitMongoRouter(router *gin.RouterGroup) {
// 获取所有mongo列表 // 获取所有mongo列表
m.GET("", func(c *gin.Context) { m.GET("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c). req.NewCtxWithGin(c).
Handle(ma.Mongos) Handle(ma.Mongos)
}) })
saveMongo := ctx.NewLogInfo("mongo-保存信息") saveMongo := req.NewLogInfo("mongo-保存信息")
m.POST("", func(c *gin.Context) { m.POST("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c). req.NewCtxWithGin(c).
WithLog(saveMongo). WithLog(saveMongo).
Handle(ma.Save) Handle(ma.Save)
}) })
deleteMongo := ctx.NewLogInfo("mongo-删除信息") deleteMongo := req.NewLogInfo("mongo-删除信息")
m.DELETE(":id", func(c *gin.Context) { m.DELETE(":id", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c). req.NewCtxWithGin(c).
WithLog(deleteMongo). WithLog(deleteMongo).
Handle(ma.DeleteMongo) Handle(ma.DeleteMongo)
}) })
// 获取mongo下的所有数据库 // 获取mongo下的所有数据库
m.GET(":id/databases", func(c *gin.Context) { m.GET(":id/databases", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c). req.NewCtxWithGin(c).
Handle(ma.Databases) Handle(ma.Databases)
}) })
// 获取mongo指定库的所有集合 // 获取mongo指定库的所有集合
m.GET(":id/collections", func(c *gin.Context) { m.GET(":id/collections", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c). req.NewCtxWithGin(c).
Handle(ma.Collections) Handle(ma.Collections)
}) })
// 获取mongo runCommand // 获取mongo runCommand
m.POST(":id/run-command", func(c *gin.Context) { m.POST(":id/run-command", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c). req.NewCtxWithGin(c).
Handle(ma.RunCommand) Handle(ma.RunCommand)
}) })
// 执行mongo find命令 // 执行mongo find命令
m.POST(":id/command/find", func(c *gin.Context) { m.POST(":id/command/find", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c). req.NewCtxWithGin(c).
Handle(ma.FindCommand) Handle(ma.FindCommand)
}) })
// 执行mongo update by id命令 // 执行mongo update by id命令
updateDocById := ctx.NewLogInfo("mongo-更新文档").WithSave(true) updateDocById := req.NewLogInfo("mongo-更新文档").WithSave(true)
m.POST(":id/command/update-by-id", func(c *gin.Context) { m.POST(":id/command/update-by-id", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c). req.NewCtxWithGin(c).
WithLog(updateDocById). WithLog(updateDocById).
Handle(ma.UpdateByIdCommand) Handle(ma.UpdateByIdCommand)
}) })
// 执行mongo delete by id命令 // 执行mongo delete by id命令
deleteDoc := ctx.NewLogInfo("mongo-删除文档").WithSave(true) deleteDoc := req.NewLogInfo("mongo-删除文档").WithSave(true)
m.POST(":id/command/delete-by-id", func(c *gin.Context) { m.POST(":id/command/delete-by-id", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c). req.NewCtxWithGin(c).
WithLog(deleteDoc). WithLog(deleteDoc).
Handle(ma.DeleteByIdCommand) Handle(ma.DeleteByIdCommand)
}) })
// 执行mongo insert 命令 // 执行mongo insert 命令
insertDoc := ctx.NewLogInfo("mongo-新增文档").WithSave(true) insertDoc := req.NewLogInfo("mongo-新增文档").WithSave(true)
m.POST(":id/command/insert", func(c *gin.Context) { m.POST(":id/command/insert", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c). req.NewCtxWithGin(c).
WithLog(insertDoc). WithLog(insertDoc).
Handle(ma.InsertOneCommand) Handle(ma.InsertOneCommand)
}) })

View File

@@ -9,9 +9,9 @@ import (
"mayfly-go/internal/redis/domain/entity" "mayfly-go/internal/redis/domain/entity"
tagapp "mayfly-go/internal/tag/application" tagapp "mayfly-go/internal/tag/application"
"mayfly-go/pkg/biz" "mayfly-go/pkg/biz"
"mayfly-go/pkg/ctx"
"mayfly-go/pkg/ginx" "mayfly-go/pkg/ginx"
"mayfly-go/pkg/model" "mayfly-go/pkg/model"
"mayfly-go/pkg/req"
"mayfly-go/pkg/utils" "mayfly-go/pkg/utils"
"strconv" "strconv"
"strings" "strings"
@@ -26,7 +26,7 @@ type Redis struct {
TagApp tagapp.TagTree TagApp tagapp.TagTree
} }
func (r *Redis) RedisList(rc *ctx.ReqCtx) { func (r *Redis) RedisList(rc *req.Ctx) {
condition := new(entity.RedisQuery) condition := new(entity.RedisQuery)
condition.TagPathLike = rc.GinCtx.Query("tagPath") condition.TagPathLike = rc.GinCtx.Query("tagPath")
@@ -40,7 +40,7 @@ func (r *Redis) RedisList(rc *ctx.ReqCtx) {
rc.ResData = r.RedisApp.GetPageList(condition, ginx.GetPageParam(rc.GinCtx), new([]vo.Redis)) rc.ResData = r.RedisApp.GetPageList(condition, ginx.GetPageParam(rc.GinCtx), new([]vo.Redis))
} }
func (r *Redis) Save(rc *ctx.ReqCtx) { func (r *Redis) Save(rc *req.Ctx) {
form := &form.Redis{} form := &form.Redis{}
ginx.BindJsonAndValid(rc.GinCtx, form) ginx.BindJsonAndValid(rc.GinCtx, form)
@@ -61,18 +61,18 @@ func (r *Redis) Save(rc *ctx.ReqCtx) {
} }
// 获取redis实例密码由于数据库是加密存储故提供该接口展示原文密码 // 获取redis实例密码由于数据库是加密存储故提供该接口展示原文密码
func (r *Redis) GetRedisPwd(rc *ctx.ReqCtx) { func (r *Redis) GetRedisPwd(rc *req.Ctx) {
rid := uint64(ginx.PathParamInt(rc.GinCtx, "id")) rid := uint64(ginx.PathParamInt(rc.GinCtx, "id"))
re := r.RedisApp.GetById(rid, "Password") re := r.RedisApp.GetById(rid, "Password")
re.PwdDecrypt() re.PwdDecrypt()
rc.ResData = re.Password rc.ResData = re.Password
} }
func (r *Redis) DeleteRedis(rc *ctx.ReqCtx) { func (r *Redis) DeleteRedis(rc *req.Ctx) {
r.RedisApp.Delete(uint64(ginx.PathParamInt(rc.GinCtx, "id"))) r.RedisApp.Delete(uint64(ginx.PathParamInt(rc.GinCtx, "id")))
} }
func (r *Redis) RedisInfo(rc *ctx.ReqCtx) { func (r *Redis) RedisInfo(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")), 0) ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")), 0)
@@ -144,7 +144,7 @@ func (r *Redis) RedisInfo(rc *ctx.ReqCtx) {
rc.ResData = parseMap rc.ResData = parseMap
} }
func (r *Redis) ClusterInfo(rc *ctx.ReqCtx) { func (r *Redis) ClusterInfo(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")), 0) ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")), 0)
biz.IsEquals(ri.Info.Mode, entity.RedisModeCluster, "非集群模式") biz.IsEquals(ri.Info.Mode, entity.RedisModeCluster, "非集群模式")
@@ -189,7 +189,7 @@ func (r *Redis) ClusterInfo(rc *ctx.ReqCtx) {
} }
// scan获取redis的key列表信息 // scan获取redis的key列表信息
func (r *Redis) Scan(rc *ctx.ReqCtx) { func (r *Redis) Scan(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")), ginx.PathParamInt(g, "db")) ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")), ginx.PathParamInt(g, "db"))
biz.ErrIsNilAppendErr(r.TagApp.CanAccess(rc.LoginAccount.Id, ri.Info.TagPath), "%s") biz.ErrIsNilAppendErr(r.TagApp.CanAccess(rc.LoginAccount.Id, ri.Info.TagPath), "%s")
@@ -318,7 +318,7 @@ func (r *Redis) Scan(rc *ctx.ReqCtx) {
rc.ResData = &vo.Keys{Cursor: cursorRes, Keys: kis, DbSize: size} rc.ResData = &vo.Keys{Cursor: cursorRes, Keys: kis, DbSize: size}
} }
func (r *Redis) DeleteKey(rc *ctx.ReqCtx) { func (r *Redis) DeleteKey(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
key := g.Query("key") key := g.Query("key")
biz.NotEmpty(key, "key不能为空") biz.NotEmpty(key, "key不能为空")
@@ -330,7 +330,7 @@ func (r *Redis) DeleteKey(rc *ctx.ReqCtx) {
ri.GetCmdable().Del(context.Background(), key) ri.GetCmdable().Del(context.Background(), key)
} }
func (r *Redis) checkKey(rc *ctx.ReqCtx) (*application.RedisInstance, string) { func (r *Redis) checkKey(rc *req.Ctx) (*application.RedisInstance, string) {
g := rc.GinCtx g := rc.GinCtx
key := g.Query("key") key := g.Query("key")
biz.NotEmpty(key, "key不能为空") biz.NotEmpty(key, "key不能为空")
@@ -341,14 +341,14 @@ func (r *Redis) checkKey(rc *ctx.ReqCtx) (*application.RedisInstance, string) {
return ri, key return ri, key
} }
func (r *Redis) GetStringValue(rc *ctx.ReqCtx) { func (r *Redis) GetStringValue(rc *req.Ctx) {
ri, key := r.checkKey(rc) ri, key := r.checkKey(rc)
str, err := ri.GetCmdable().Get(context.TODO(), key).Result() str, err := ri.GetCmdable().Get(context.TODO(), key).Result()
biz.ErrIsNilAppendErr(err, "获取字符串值失败: %s") biz.ErrIsNilAppendErr(err, "获取字符串值失败: %s")
rc.ResData = str rc.ResData = str
} }
func (r *Redis) SetStringValue(rc *ctx.ReqCtx) { func (r *Redis) SetStringValue(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
keyValue := new(form.StringValue) keyValue := new(form.StringValue)
ginx.BindJsonAndValid(g, keyValue) ginx.BindJsonAndValid(g, keyValue)
@@ -363,7 +363,7 @@ func (r *Redis) SetStringValue(rc *ctx.ReqCtx) {
rc.ResData = str rc.ResData = str
} }
func (r *Redis) Hscan(rc *ctx.ReqCtx) { func (r *Redis) Hscan(rc *req.Ctx) {
ri, key := r.checkKey(rc) ri, key := r.checkKey(rc)
g := rc.GinCtx g := rc.GinCtx
count := ginx.QueryInt(g, "count", 10) count := ginx.QueryInt(g, "count", 10)
@@ -384,7 +384,7 @@ func (r *Redis) Hscan(rc *ctx.ReqCtx) {
} }
} }
func (r *Redis) Hdel(rc *ctx.ReqCtx) { func (r *Redis) Hdel(rc *req.Ctx) {
ri, key := r.checkKey(rc) ri, key := r.checkKey(rc)
field := rc.GinCtx.Query("field") field := rc.GinCtx.Query("field")
@@ -393,7 +393,7 @@ func (r *Redis) Hdel(rc *ctx.ReqCtx) {
rc.ResData = delRes rc.ResData = delRes
} }
func (r *Redis) Hget(rc *ctx.ReqCtx) { func (r *Redis) Hget(rc *req.Ctx) {
ri, key := r.checkKey(rc) ri, key := r.checkKey(rc)
field := rc.GinCtx.Query("field") field := rc.GinCtx.Query("field")
@@ -402,7 +402,7 @@ func (r *Redis) Hget(rc *ctx.ReqCtx) {
rc.ResData = res rc.ResData = res
} }
func (r *Redis) SetHashValue(rc *ctx.ReqCtx) { func (r *Redis) SetHashValue(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
hashValue := new(form.HashValue) hashValue := new(form.HashValue)
ginx.BindJsonAndValid(g, hashValue) ginx.BindJsonAndValid(g, hashValue)
@@ -422,14 +422,14 @@ func (r *Redis) SetHashValue(rc *ctx.ReqCtx) {
} }
} }
func (r *Redis) GetSetValue(rc *ctx.ReqCtx) { func (r *Redis) GetSetValue(rc *req.Ctx) {
ri, key := r.checkKey(rc) ri, key := r.checkKey(rc)
res, err := ri.GetCmdable().SMembers(context.TODO(), key).Result() res, err := ri.GetCmdable().SMembers(context.TODO(), key).Result()
biz.ErrIsNilAppendErr(err, "获取set值失败: %s") biz.ErrIsNilAppendErr(err, "获取set值失败: %s")
rc.ResData = res rc.ResData = res
} }
func (r *Redis) SetSetValue(rc *ctx.ReqCtx) { func (r *Redis) SetSetValue(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
keyvalue := new(form.SetValue) keyvalue := new(form.SetValue)
ginx.BindJsonAndValid(g, keyvalue) ginx.BindJsonAndValid(g, keyvalue)
@@ -448,7 +448,7 @@ func (r *Redis) SetSetValue(rc *ctx.ReqCtx) {
} }
} }
func (r *Redis) GetListValue(rc *ctx.ReqCtx) { func (r *Redis) GetListValue(rc *req.Ctx) {
ri, key := r.checkKey(rc) ri, key := r.checkKey(rc)
ctx := context.TODO() ctx := context.TODO()
cmdable := ri.GetCmdable() cmdable := ri.GetCmdable()
@@ -468,7 +468,7 @@ func (r *Redis) GetListValue(rc *ctx.ReqCtx) {
} }
} }
func (r *Redis) SaveListValue(rc *ctx.ReqCtx) { func (r *Redis) SaveListValue(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
listValue := new(form.ListValue) listValue := new(form.ListValue)
ginx.BindJsonAndValid(g, listValue) ginx.BindJsonAndValid(g, listValue)
@@ -488,7 +488,7 @@ func (r *Redis) SaveListValue(rc *ctx.ReqCtx) {
} }
} }
func (r *Redis) SetListValue(rc *ctx.ReqCtx) { func (r *Redis) SetListValue(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
listSetValue := new(form.ListSetValue) listSetValue := new(form.ListSetValue)
ginx.BindJsonAndValid(g, listSetValue) ginx.BindJsonAndValid(g, listSetValue)

View File

@@ -4,7 +4,7 @@ import (
"mayfly-go/internal/redis/api" "mayfly-go/internal/redis/api"
"mayfly-go/internal/redis/application" "mayfly-go/internal/redis/application"
tagapp "mayfly-go/internal/tag/application" tagapp "mayfly-go/internal/tag/application"
"mayfly-go/pkg/ctx" "mayfly-go/pkg/req"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@@ -19,94 +19,94 @@ func InitRedisRouter(router *gin.RouterGroup) {
// 获取redis list // 获取redis list
redis.GET("", func(c *gin.Context) { redis.GET("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(rs.RedisList) req.NewCtxWithGin(c).Handle(rs.RedisList)
}) })
save := ctx.NewLogInfo("redis-保存信息").WithSave(true) save := req.NewLogInfo("redis-保存信息").WithSave(true)
redis.POST("", func(c *gin.Context) { redis.POST("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(save).Handle(rs.Save) req.NewCtxWithGin(c).WithLog(save).Handle(rs.Save)
}) })
redis.GET(":id/pwd", func(c *gin.Context) { redis.GET(":id/pwd", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(rs.GetRedisPwd) req.NewCtxWithGin(c).Handle(rs.GetRedisPwd)
}) })
delRedis := ctx.NewLogInfo("redis-删除信息").WithSave(true) delRedis := req.NewLogInfo("redis-删除信息").WithSave(true)
redis.DELETE(":id", func(c *gin.Context) { redis.DELETE(":id", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(delRedis).Handle(rs.DeleteRedis) req.NewCtxWithGin(c).WithLog(delRedis).Handle(rs.DeleteRedis)
}) })
redis.GET(":id/info", func(c *gin.Context) { redis.GET(":id/info", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(rs.RedisInfo) req.NewCtxWithGin(c).Handle(rs.RedisInfo)
}) })
redis.GET(":id/cluster-info", func(c *gin.Context) { redis.GET(":id/cluster-info", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(rs.ClusterInfo) req.NewCtxWithGin(c).Handle(rs.ClusterInfo)
}) })
// 获取指定redis keys // 获取指定redis keys
redis.POST(":id/:db/scan", func(c *gin.Context) { redis.POST(":id/:db/scan", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(rs.Scan) req.NewCtxWithGin(c).Handle(rs.Scan)
}) })
// 删除key // 删除key
deleteKeyL := ctx.NewLogInfo("redis-删除key").WithSave(true) deleteKeyL := req.NewLogInfo("redis-删除key").WithSave(true)
redis.DELETE(":id/:db/key", func(c *gin.Context) { redis.DELETE(":id/:db/key", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(deleteKeyL).Handle(rs.DeleteKey) req.NewCtxWithGin(c).WithLog(deleteKeyL).Handle(rs.DeleteKey)
}) })
// 获取string类型值 // 获取string类型值
redis.GET(":id/:db/string-value", func(c *gin.Context) { redis.GET(":id/:db/string-value", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(rs.GetStringValue) req.NewCtxWithGin(c).Handle(rs.GetStringValue)
}) })
// 设置string类型值 // 设置string类型值
setStringL := ctx.NewLogInfo("redis-setString").WithSave(true) setStringL := req.NewLogInfo("redis-setString").WithSave(true)
redis.POST(":id/:db/string-value", func(c *gin.Context) { redis.POST(":id/:db/string-value", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(setStringL).Handle(rs.SetStringValue) req.NewCtxWithGin(c).WithLog(setStringL).Handle(rs.SetStringValue)
}) })
// hscan // hscan
redis.GET(":id/:db/hscan", func(c *gin.Context) { redis.GET(":id/:db/hscan", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(rs.Hscan) req.NewCtxWithGin(c).Handle(rs.Hscan)
}) })
redis.GET(":id/:db/hget", func(c *gin.Context) { redis.GET(":id/:db/hget", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(rs.Hget) req.NewCtxWithGin(c).Handle(rs.Hget)
}) })
hdelL := ctx.NewLogInfo("redis-hdel").WithSave(true) hdelL := req.NewLogInfo("redis-hdel").WithSave(true)
redis.DELETE(":id/:db/hdel", func(c *gin.Context) { redis.DELETE(":id/:db/hdel", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(hdelL).Handle(rs.Hdel) req.NewCtxWithGin(c).WithLog(hdelL).Handle(rs.Hdel)
}) })
// 设置hash类型值 // 设置hash类型值
setHashValueL := ctx.NewLogInfo("redis-setHashValue").WithSave(true) setHashValueL := req.NewLogInfo("redis-setHashValue").WithSave(true)
redis.POST(":id/:db/hash-value", func(c *gin.Context) { redis.POST(":id/:db/hash-value", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(setHashValueL).Handle(rs.SetHashValue) req.NewCtxWithGin(c).WithLog(setHashValueL).Handle(rs.SetHashValue)
}) })
// 获取set类型值 // 获取set类型值
redis.GET(":id/:db/set-value", func(c *gin.Context) { redis.GET(":id/:db/set-value", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(rs.GetSetValue) req.NewCtxWithGin(c).Handle(rs.GetSetValue)
}) })
// 设置set类型值 // 设置set类型值
redis.POST(":id/:db/set-value", func(c *gin.Context) { redis.POST(":id/:db/set-value", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(rs.SetSetValue) req.NewCtxWithGin(c).Handle(rs.SetSetValue)
}) })
// 获取list类型值 // 获取list类型值
redis.GET(":id/:db/list-value", func(c *gin.Context) { redis.GET(":id/:db/list-value", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(rs.GetListValue) req.NewCtxWithGin(c).Handle(rs.GetListValue)
}) })
redis.POST(":id/:db/list-value", func(c *gin.Context) { redis.POST(":id/:db/list-value", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(rs.SaveListValue) req.NewCtxWithGin(c).Handle(rs.SaveListValue)
}) })
redis.POST(":id/:db/list-value/lset", func(c *gin.Context) { redis.POST(":id/:db/list-value/lset", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(rs.SetListValue) req.NewCtxWithGin(c).Handle(rs.SetListValue)
}) })
} }
} }

View File

@@ -8,9 +8,9 @@ import (
"mayfly-go/internal/sys/domain/entity" "mayfly-go/internal/sys/domain/entity"
"mayfly-go/pkg/biz" "mayfly-go/pkg/biz"
"mayfly-go/pkg/captcha" "mayfly-go/pkg/captcha"
"mayfly-go/pkg/ctx"
"mayfly-go/pkg/ginx" "mayfly-go/pkg/ginx"
"mayfly-go/pkg/model" "mayfly-go/pkg/model"
"mayfly-go/pkg/req"
"mayfly-go/pkg/utils" "mayfly-go/pkg/utils"
"regexp" "regexp"
"strconv" "strconv"
@@ -29,7 +29,7 @@ type Account struct {
/** 登录者个人相关操作 **/ /** 登录者个人相关操作 **/
// @router /accounts/login [post] // @router /accounts/login [post]
func (a *Account) Login(rc *ctx.ReqCtx) { func (a *Account) Login(rc *req.Ctx) {
loginForm := &form.LoginForm{} loginForm := &form.LoginForm{}
ginx.BindJsonAndValid(rc.GinCtx, loginForm) ginx.BindJsonAndValid(rc.GinCtx, loginForm)
@@ -65,7 +65,7 @@ func (a *Account) Login(rc *ctx.ReqCtx) {
} }
} }
// 保存该账号的权限codes // 保存该账号的权限codes
ctx.SavePermissionCodes(account.Id, permissions) req.SavePermissionCodes(account.Id, permissions)
clientIp := rc.GinCtx.ClientIP() clientIp := rc.GinCtx.ClientIP()
// 保存登录消息 // 保存登录消息
@@ -76,7 +76,7 @@ func (a *Account) Login(rc *ctx.ReqCtx) {
rc.LoginAccount = &model.LoginAccount{Id: account.Id, Username: account.Username} rc.LoginAccount = &model.LoginAccount{Id: account.Id, Username: account.Username}
rc.ResData = map[string]interface{}{ rc.ResData = map[string]interface{}{
"token": ctx.CreateToken(account.Id, account.Username), "token": req.CreateToken(account.Id, account.Username),
"name": account.Name, "name": account.Name,
"username": account.Username, "username": account.Username,
"lastLoginTime": account.LastLoginTime, "lastLoginTime": account.LastLoginTime,
@@ -86,7 +86,7 @@ func (a *Account) Login(rc *ctx.ReqCtx) {
} }
} }
func (a *Account) ChangePassword(rc *ctx.ReqCtx) { func (a *Account) ChangePassword(rc *req.Ctx) {
form := new(form.AccountChangePasswordForm) form := new(form.AccountChangePasswordForm)
ginx.BindJsonAndValid(rc.GinCtx, form) ginx.BindJsonAndValid(rc.GinCtx, form)
@@ -153,7 +153,7 @@ func (a *Account) saveLogin(account *entity.Account, ip string) {
} }
// 获取个人账号信息 // 获取个人账号信息
func (a *Account) AccountInfo(rc *ctx.ReqCtx) { func (a *Account) AccountInfo(rc *req.Ctx) {
ap := new(vo.AccountPersonVO) ap := new(vo.AccountPersonVO)
// 角色信息 // 角色信息
roles := new([]vo.AccountRoleVO) roles := new([]vo.AccountRoleVO)
@@ -164,7 +164,7 @@ func (a *Account) AccountInfo(rc *ctx.ReqCtx) {
} }
// 更新个人账号信息 // 更新个人账号信息
func (a *Account) UpdateAccount(rc *ctx.ReqCtx) { func (a *Account) UpdateAccount(rc *req.Ctx) {
updateForm := &form.AccountUpdateForm{} updateForm := &form.AccountUpdateForm{}
ginx.BindJsonAndValid(rc.GinCtx, updateForm) ginx.BindJsonAndValid(rc.GinCtx, updateForm)
@@ -181,7 +181,7 @@ func (a *Account) UpdateAccount(rc *ctx.ReqCtx) {
} }
// 获取账号接收的消息列表 // 获取账号接收的消息列表
func (a *Account) GetMsgs(rc *ctx.ReqCtx) { func (a *Account) GetMsgs(rc *req.Ctx) {
condition := &entity.Msg{ condition := &entity.Msg{
RecipientId: int64(rc.LoginAccount.Id), RecipientId: int64(rc.LoginAccount.Id),
} }
@@ -191,14 +191,14 @@ func (a *Account) GetMsgs(rc *ctx.ReqCtx) {
/** 后台账号操作 **/ /** 后台账号操作 **/
// @router /accounts [get] // @router /accounts [get]
func (a *Account) Accounts(rc *ctx.ReqCtx) { func (a *Account) Accounts(rc *req.Ctx) {
condition := &entity.Account{} condition := &entity.Account{}
condition.Username = rc.GinCtx.Query("username") condition.Username = rc.GinCtx.Query("username")
rc.ResData = a.AccountApp.GetPageList(condition, ginx.GetPageParam(rc.GinCtx), new([]vo.AccountManageVO)) rc.ResData = a.AccountApp.GetPageList(condition, ginx.GetPageParam(rc.GinCtx), new([]vo.AccountManageVO))
} }
// @router /accounts // @router /accounts
func (a *Account) SaveAccount(rc *ctx.ReqCtx) { func (a *Account) SaveAccount(rc *req.Ctx) {
form := &form.AccountCreateForm{} form := &form.AccountCreateForm{}
ginx.BindJsonAndValid(rc.GinCtx, form) ginx.BindJsonAndValid(rc.GinCtx, form)
rc.ReqParam = form rc.ReqParam = form
@@ -218,7 +218,7 @@ func (a *Account) SaveAccount(rc *ctx.ReqCtx) {
} }
} }
func (a *Account) ChangeStatus(rc *ctx.ReqCtx) { func (a *Account) ChangeStatus(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
account := &entity.Account{} account := &entity.Account{}
@@ -228,25 +228,25 @@ func (a *Account) ChangeStatus(rc *ctx.ReqCtx) {
a.AccountApp.Update(account) a.AccountApp.Update(account)
} }
func (a *Account) DeleteAccount(rc *ctx.ReqCtx) { func (a *Account) DeleteAccount(rc *req.Ctx) {
id := uint64(ginx.PathParamInt(rc.GinCtx, "id")) id := uint64(ginx.PathParamInt(rc.GinCtx, "id"))
rc.ReqParam = id rc.ReqParam = id
a.AccountApp.Delete(id) a.AccountApp.Delete(id)
} }
// 获取账号角色id列表用户回显角色分配 // 获取账号角色id列表用户回显角色分配
func (a *Account) AccountRoleIds(rc *ctx.ReqCtx) { func (a *Account) AccountRoleIds(rc *req.Ctx) {
rc.ResData = a.RoleApp.GetAccountRoleIds(uint64(ginx.PathParamInt(rc.GinCtx, "id"))) rc.ResData = a.RoleApp.GetAccountRoleIds(uint64(ginx.PathParamInt(rc.GinCtx, "id")))
} }
// 获取账号角色id列表用户回显角色分配 // 获取账号角色id列表用户回显角色分配
func (a *Account) AccountRoles(rc *ctx.ReqCtx) { func (a *Account) AccountRoles(rc *req.Ctx) {
vos := new([]vo.AccountRoleVO) vos := new([]vo.AccountRoleVO)
a.RoleApp.GetAccountRoles(uint64(ginx.PathParamInt(rc.GinCtx, "id")), vos) a.RoleApp.GetAccountRoles(uint64(ginx.PathParamInt(rc.GinCtx, "id")), vos)
rc.ResData = vos rc.ResData = vos
} }
func (a *Account) AccountResources(rc *ctx.ReqCtx) { func (a *Account) AccountResources(rc *req.Ctx) {
var resources vo.ResourceManageVOList var resources vo.ResourceManageVOList
// 获取账号菜单资源 // 获取账号菜单资源
a.ResourceApp.GetAccountResources(uint64(ginx.PathParamInt(rc.GinCtx, "id")), &resources) a.ResourceApp.GetAccountResources(uint64(ginx.PathParamInt(rc.GinCtx, "id")), &resources)
@@ -254,7 +254,7 @@ func (a *Account) AccountResources(rc *ctx.ReqCtx) {
} }
// 保存账号角色信息 // 保存账号角色信息
func (a *Account) SaveRoles(rc *ctx.ReqCtx) { func (a *Account) SaveRoles(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
var form form.AccountRoleForm var form form.AccountRoleForm

View File

@@ -2,10 +2,10 @@ package api
import ( import (
"mayfly-go/pkg/captcha" "mayfly-go/pkg/captcha"
"mayfly-go/pkg/ctx" "mayfly-go/pkg/req"
) )
func GenerateCaptcha(rc *ctx.ReqCtx) { func GenerateCaptcha(rc *req.Ctx) {
id, image := captcha.Generate() id, image := captcha.Generate()
rc.ResData = map[string]interface{}{"base64Captcha": image, "cid": id} rc.ResData = map[string]interface{}{"base64Captcha": image, "cid": id}
} }

View File

@@ -5,8 +5,8 @@ import (
"mayfly-go/internal/sys/application" "mayfly-go/internal/sys/application"
"mayfly-go/internal/sys/domain/entity" "mayfly-go/internal/sys/domain/entity"
"mayfly-go/pkg/biz" "mayfly-go/pkg/biz"
"mayfly-go/pkg/ctx"
"mayfly-go/pkg/ginx" "mayfly-go/pkg/ginx"
"mayfly-go/pkg/req"
"mayfly-go/pkg/utils" "mayfly-go/pkg/utils"
) )
@@ -14,19 +14,19 @@ type Config struct {
ConfigApp application.Config ConfigApp application.Config
} }
func (c *Config) Configs(rc *ctx.ReqCtx) { func (c *Config) Configs(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
condition := &entity.Config{Key: g.Query("key")} condition := &entity.Config{Key: g.Query("key")}
rc.ResData = c.ConfigApp.GetPageList(condition, ginx.GetPageParam(g), new([]entity.Config)) rc.ResData = c.ConfigApp.GetPageList(condition, ginx.GetPageParam(g), new([]entity.Config))
} }
func (c *Config) GetConfigValueByKey(rc *ctx.ReqCtx) { func (c *Config) GetConfigValueByKey(rc *req.Ctx) {
key := rc.GinCtx.Query("key") key := rc.GinCtx.Query("key")
biz.NotEmpty(key, "key不能为空") biz.NotEmpty(key, "key不能为空")
rc.ResData = c.ConfigApp.GetConfig(key).Value rc.ResData = c.ConfigApp.GetConfig(key).Value
} }
func (c *Config) SaveConfig(rc *ctx.ReqCtx) { func (c *Config) SaveConfig(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
form := &form.ConfigForm{} form := &form.ConfigForm{}
ginx.BindJsonAndValid(g, form) ginx.BindJsonAndValid(g, form)

View File

@@ -6,8 +6,8 @@ import (
"mayfly-go/internal/sys/api/vo" "mayfly-go/internal/sys/api/vo"
"mayfly-go/internal/sys/application" "mayfly-go/internal/sys/application"
"mayfly-go/internal/sys/domain/entity" "mayfly-go/internal/sys/domain/entity"
"mayfly-go/pkg/ctx"
"mayfly-go/pkg/ginx" "mayfly-go/pkg/ginx"
"mayfly-go/pkg/req"
"mayfly-go/pkg/utils" "mayfly-go/pkg/utils"
) )
@@ -15,17 +15,17 @@ type Resource struct {
ResourceApp application.Resource ResourceApp application.Resource
} }
func (r *Resource) GetAllResourceTree(rc *ctx.ReqCtx) { func (r *Resource) GetAllResourceTree(rc *req.Ctx) {
var resources vo.ResourceManageVOList var resources vo.ResourceManageVOList
r.ResourceApp.GetResourceList(new(entity.Resource), &resources, "weight asc") r.ResourceApp.GetResourceList(new(entity.Resource), &resources, "weight asc")
rc.ResData = resources.ToTrees(0) rc.ResData = resources.ToTrees(0)
} }
func (r *Resource) GetById(rc *ctx.ReqCtx) { func (r *Resource) GetById(rc *req.Ctx) {
rc.ResData = r.ResourceApp.GetById(uint64(ginx.PathParamInt(rc.GinCtx, "id"))) rc.ResData = r.ResourceApp.GetById(uint64(ginx.PathParamInt(rc.GinCtx, "id")))
} }
func (r *Resource) SaveResource(rc *ctx.ReqCtx) { func (r *Resource) SaveResource(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
form := new(form.ResourceForm) form := new(form.ResourceForm)
ginx.BindJsonAndValid(g, form) ginx.BindJsonAndValid(g, form)
@@ -41,11 +41,11 @@ func (r *Resource) SaveResource(rc *ctx.ReqCtx) {
r.ResourceApp.Save(entity) r.ResourceApp.Save(entity)
} }
func (r *Resource) DelResource(rc *ctx.ReqCtx) { func (r *Resource) DelResource(rc *req.Ctx) {
r.ResourceApp.Delete(uint64(ginx.PathParamInt(rc.GinCtx, "id"))) r.ResourceApp.Delete(uint64(ginx.PathParamInt(rc.GinCtx, "id")))
} }
func (r *Resource) ChangeStatus(rc *ctx.ReqCtx) { func (r *Resource) ChangeStatus(rc *req.Ctx) {
re := &entity.Resource{} re := &entity.Resource{}
re.Id = uint64(ginx.PathParamInt(rc.GinCtx, "id")) re.Id = uint64(ginx.PathParamInt(rc.GinCtx, "id"))
re.Status = int8(ginx.PathParamInt(rc.GinCtx, "status")) re.Status = int8(ginx.PathParamInt(rc.GinCtx, "status"))

View File

@@ -5,8 +5,8 @@ import (
"mayfly-go/internal/sys/api/vo" "mayfly-go/internal/sys/api/vo"
"mayfly-go/internal/sys/application" "mayfly-go/internal/sys/application"
"mayfly-go/internal/sys/domain/entity" "mayfly-go/internal/sys/domain/entity"
"mayfly-go/pkg/ctx"
"mayfly-go/pkg/ginx" "mayfly-go/pkg/ginx"
"mayfly-go/pkg/req"
"mayfly-go/pkg/utils" "mayfly-go/pkg/utils"
"strconv" "strconv"
"strings" "strings"
@@ -18,14 +18,14 @@ type Role struct {
ResourceApp application.Resource ResourceApp application.Resource
} }
func (r *Role) Roles(rc *ctx.ReqCtx) { func (r *Role) Roles(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
condition := &entity.Role{} condition := &entity.Role{}
rc.ResData = r.RoleApp.GetPageList(condition, ginx.GetPageParam(g), new([]entity.Role)) rc.ResData = r.RoleApp.GetPageList(condition, ginx.GetPageParam(g), new([]entity.Role))
} }
// 保存角色信息 // 保存角色信息
func (r *Role) SaveRole(rc *ctx.ReqCtx) { func (r *Role) SaveRole(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
form := &form.RoleForm{} form := &form.RoleForm{}
ginx.BindJsonAndValid(g, form) ginx.BindJsonAndValid(g, form)
@@ -39,17 +39,17 @@ func (r *Role) SaveRole(rc *ctx.ReqCtx) {
} }
// 删除角色及其资源关联关系 // 删除角色及其资源关联关系
func (r *Role) DelRole(rc *ctx.ReqCtx) { func (r *Role) DelRole(rc *req.Ctx) {
r.RoleApp.DeleteRole(uint64(ginx.PathParamInt(rc.GinCtx, "id"))) r.RoleApp.DeleteRole(uint64(ginx.PathParamInt(rc.GinCtx, "id")))
} }
// 获取角色关联的资源id数组用于分配资源时回显已拥有的资源 // 获取角色关联的资源id数组用于分配资源时回显已拥有的资源
func (r *Role) RoleResourceIds(rc *ctx.ReqCtx) { func (r *Role) RoleResourceIds(rc *req.Ctx) {
rc.ResData = r.RoleApp.GetRoleResourceIds(uint64(ginx.PathParamInt(rc.GinCtx, "id"))) rc.ResData = r.RoleApp.GetRoleResourceIds(uint64(ginx.PathParamInt(rc.GinCtx, "id")))
} }
// 查看角色关联的资源树信息 // 查看角色关联的资源树信息
func (r *Role) RoleResource(rc *ctx.ReqCtx) { func (r *Role) RoleResource(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
var resources vo.ResourceManageVOList var resources vo.ResourceManageVOList
@@ -59,7 +59,7 @@ func (r *Role) RoleResource(rc *ctx.ReqCtx) {
} }
// 保存角色资源 // 保存角色资源
func (r *Role) SaveResource(rc *ctx.ReqCtx) { func (r *Role) SaveResource(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
var form form.RoleResourceForm var form form.RoleResourceForm

View File

@@ -3,15 +3,15 @@ package api
import ( import (
"mayfly-go/internal/sys/application" "mayfly-go/internal/sys/application"
"mayfly-go/internal/sys/domain/entity" "mayfly-go/internal/sys/domain/entity"
"mayfly-go/pkg/ctx"
"mayfly-go/pkg/ginx" "mayfly-go/pkg/ginx"
"mayfly-go/pkg/req"
) )
type Syslog struct { type Syslog struct {
SyslogApp application.Syslog SyslogApp application.Syslog
} }
func (r *Syslog) Syslogs(rc *ctx.ReqCtx) { func (r *Syslog) Syslogs(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
condition := &entity.Syslog{ condition := &entity.Syslog{
Type: int8(ginx.QueryInt(g, "type", 0)), Type: int8(ginx.QueryInt(g, "type", 0)),

View File

@@ -2,8 +2,8 @@ package api
import ( import (
"mayfly-go/pkg/biz" "mayfly-go/pkg/biz"
"mayfly-go/pkg/ctx"
"mayfly-go/pkg/global" "mayfly-go/pkg/global"
"mayfly-go/pkg/req"
"mayfly-go/pkg/ws" "mayfly-go/pkg/ws"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@@ -30,8 +30,8 @@ func (s *System) ConnectWs(g *gin.Context) {
panic(biz.NewBizErr("升级websocket失败")) panic(biz.NewBizErr("升级websocket失败"))
} }
// 权限校验 // 权限校验
rc := ctx.NewReqCtxWithGin(g) rc := req.NewCtxWithGin(g)
if err = ctx.PermissionHandler(rc); err != nil { if err = req.PermissionHandler(rc); err != nil {
panic(biz.NewBizErr("没有权限")) panic(biz.NewBizErr("没有权限"))
} }

View File

@@ -6,8 +6,8 @@ import (
"mayfly-go/internal/sys/domain/entity" "mayfly-go/internal/sys/domain/entity"
"mayfly-go/internal/sys/domain/repository" "mayfly-go/internal/sys/domain/repository"
"mayfly-go/pkg/biz" "mayfly-go/pkg/biz"
"mayfly-go/pkg/ctx"
"mayfly-go/pkg/model" "mayfly-go/pkg/model"
"mayfly-go/pkg/req"
"mayfly-go/pkg/utils" "mayfly-go/pkg/utils"
"reflect" "reflect"
"time" "time"
@@ -17,7 +17,7 @@ type Syslog interface {
GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
// 从请求上下文的参数保存系统日志 // 从请求上下文的参数保存系统日志
SaveFromReq(req *ctx.ReqCtx) SaveFromReq(req *req.Ctx)
} }
func newSyslogApp(syslogRepo repository.Syslog) Syslog { func newSyslogApp(syslogRepo repository.Syslog) Syslog {
@@ -34,7 +34,7 @@ func (m *syslogAppImpl) GetPageList(condition *entity.Syslog, pageParam *model.P
return m.syslogRepo.GetPageList(condition, pageParam, toEntity, orderBy...) return m.syslogRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
} }
func (m *syslogAppImpl) SaveFromReq(req *ctx.ReqCtx) { func (m *syslogAppImpl) SaveFromReq(req *req.Ctx) {
lg := req.LoginAccount lg := req.LoginAccount
if lg == nil { if lg == nil {
return return

View File

@@ -3,7 +3,7 @@ package router
import ( import (
"mayfly-go/internal/sys/api" "mayfly-go/internal/sys/api"
"mayfly-go/internal/sys/application" "mayfly-go/internal/sys/application"
"mayfly-go/pkg/ctx" "mayfly-go/pkg/req"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@@ -19,17 +19,17 @@ func InitAccountRouter(router *gin.RouterGroup) {
} }
{ {
// 用户登录 // 用户登录
loginLog := ctx.NewLogInfo("用户登录").WithSave(true) loginLog := req.NewLogInfo("用户登录").WithSave(true)
account.POST("login", func(g *gin.Context) { account.POST("login", func(g *gin.Context) {
ctx.NewReqCtxWithGin(g). req.NewCtxWithGin(g).
WithNeedToken(false). WithNeedToken(false).
WithLog(loginLog). WithLog(loginLog).
Handle(a.Login) Handle(a.Login)
}) })
changePwdLog := ctx.NewLogInfo("用户修改密码").WithSave(true) changePwdLog := req.NewLogInfo("用户修改密码").WithSave(true)
account.POST("change-pwd", func(g *gin.Context) { account.POST("change-pwd", func(g *gin.Context) {
ctx.NewReqCtxWithGin(g). req.NewCtxWithGin(g).
WithNeedToken(false). WithNeedToken(false).
WithLog(changePwdLog). WithLog(changePwdLog).
Handle(a.ChangePassword) Handle(a.ChangePassword)
@@ -37,45 +37,45 @@ func InitAccountRouter(router *gin.RouterGroup) {
// 获取个人账号信息 // 获取个人账号信息
account.GET("/self", func(c *gin.Context) { account.GET("/self", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(a.AccountInfo) req.NewCtxWithGin(c).Handle(a.AccountInfo)
}) })
// 更新个人账号信息 // 更新个人账号信息
account.PUT("/self", func(c *gin.Context) { account.PUT("/self", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(a.UpdateAccount) req.NewCtxWithGin(c).Handle(a.UpdateAccount)
}) })
account.GET("/msgs", func(c *gin.Context) { account.GET("/msgs", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(a.GetMsgs) req.NewCtxWithGin(c).Handle(a.GetMsgs)
}) })
/** 后台管理接口 **/ /** 后台管理接口 **/
// 获取所有用户列表 // 获取所有用户列表
account.GET("", func(c *gin.Context) { account.GET("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(a.Accounts) req.NewCtxWithGin(c).Handle(a.Accounts)
}) })
createAccount := ctx.NewLogInfo("保存账号信息").WithSave(true) createAccount := req.NewLogInfo("保存账号信息").WithSave(true)
addAccountPermission := ctx.NewPermission("account:add") addAccountPermission := req.NewPermission("account:add")
account.POST("", func(c *gin.Context) { account.POST("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c). req.NewCtxWithGin(c).
WithRequiredPermission(addAccountPermission). WithRequiredPermission(addAccountPermission).
WithLog(createAccount). WithLog(createAccount).
Handle(a.SaveAccount) Handle(a.SaveAccount)
}) })
changeStatus := ctx.NewLogInfo("修改账号状态").WithSave(true) changeStatus := req.NewLogInfo("修改账号状态").WithSave(true)
account.PUT("change-status/:id/:status", func(c *gin.Context) { account.PUT("change-status/:id/:status", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c). req.NewCtxWithGin(c).
WithLog(changeStatus). WithLog(changeStatus).
Handle(a.ChangeStatus) Handle(a.ChangeStatus)
}) })
delAccount := ctx.NewLogInfo("删除账号").WithSave(true) delAccount := req.NewLogInfo("删除账号").WithSave(true)
delAccountPermission := ctx.NewPermission("account:del") delAccountPermission := req.NewPermission("account:del")
account.DELETE(":id", func(c *gin.Context) { account.DELETE(":id", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c). req.NewCtxWithGin(c).
WithRequiredPermission(delAccountPermission). WithRequiredPermission(delAccountPermission).
WithLog(delAccount). WithLog(delAccount).
Handle(a.DeleteAccount) Handle(a.DeleteAccount)
@@ -83,26 +83,26 @@ func InitAccountRouter(router *gin.RouterGroup) {
// 获取所有用户角色id列表 // 获取所有用户角色id列表
account.GET(":id/roleIds", func(c *gin.Context) { account.GET(":id/roleIds", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(a.AccountRoleIds) req.NewCtxWithGin(c).Handle(a.AccountRoleIds)
}) })
// 保存用户角色 // 保存用户角色
saveAccountRole := ctx.NewLogInfo("保存用户角色").WithSave(true) saveAccountRole := req.NewLogInfo("保存用户角色").WithSave(true)
sarPermission := ctx.NewPermission("account:saveRoles") sarPermission := req.NewPermission("account:saveRoles")
account.POST("/roles", func(c *gin.Context) { account.POST("/roles", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(saveAccountRole). req.NewCtxWithGin(c).WithLog(saveAccountRole).
WithRequiredPermission(sarPermission). WithRequiredPermission(sarPermission).
Handle(a.SaveRoles) Handle(a.SaveRoles)
}) })
// 获取用户角色 // 获取用户角色
account.GET(":id/roles", func(c *gin.Context) { account.GET(":id/roles", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(a.AccountRoles) req.NewCtxWithGin(c).Handle(a.AccountRoles)
}) })
// 获取用户资源列表 // 获取用户资源列表
account.GET(":id/resources", func(c *gin.Context) { account.GET(":id/resources", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(a.AccountResources) req.NewCtxWithGin(c).Handle(a.AccountResources)
}) })
} }
} }

View File

@@ -2,7 +2,7 @@ package router
import ( import (
"mayfly-go/internal/sys/api" "mayfly-go/internal/sys/api"
"mayfly-go/pkg/ctx" "mayfly-go/pkg/req"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@@ -11,7 +11,7 @@ func InitCaptchaRouter(router *gin.RouterGroup) {
captcha := router.Group("sys/captcha") captcha := router.Group("sys/captcha")
{ {
captcha.GET("", func(c *gin.Context) { captcha.GET("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithNeedToken(false).Handle(api.GenerateCaptcha) req.NewCtxWithGin(c).WithNeedToken(false).Handle(api.GenerateCaptcha)
}) })
} }
} }

View File

@@ -3,7 +3,7 @@ package router
import ( import (
"mayfly-go/internal/sys/api" "mayfly-go/internal/sys/api"
"mayfly-go/internal/sys/application" "mayfly-go/internal/sys/application"
"mayfly-go/pkg/ctx" "mayfly-go/pkg/req"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@@ -13,16 +13,16 @@ func InitSysConfigRouter(router *gin.RouterGroup) {
db := router.Group("sys/configs") db := router.Group("sys/configs")
{ {
db.GET("", func(c *gin.Context) { db.GET("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(r.Configs) req.NewCtxWithGin(c).Handle(r.Configs)
}) })
db.GET("/value", func(c *gin.Context) { db.GET("/value", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithNeedToken(false).Handle(r.GetConfigValueByKey) req.NewCtxWithGin(c).WithNeedToken(false).Handle(r.GetConfigValueByKey)
}) })
saveConfig := ctx.NewLogInfo("保存系统配置信息").WithSave(true) saveConfig := req.NewLogInfo("保存系统配置信息").WithSave(true)
db.POST("", func(c *gin.Context) { db.POST("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c). req.NewCtxWithGin(c).
WithLog(saveConfig). WithLog(saveConfig).
Handle(r.SaveConfig) Handle(r.SaveConfig)
}) })

View File

@@ -3,7 +3,7 @@ package router
import ( import (
"mayfly-go/internal/sys/api" "mayfly-go/internal/sys/api"
"mayfly-go/internal/sys/application" "mayfly-go/internal/sys/application"
"mayfly-go/pkg/ctx" "mayfly-go/pkg/req"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@@ -13,35 +13,35 @@ func InitResourceRouter(router *gin.RouterGroup) {
db := router.Group("sys/resources") db := router.Group("sys/resources")
{ {
db.GET("", func(c *gin.Context) { db.GET("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(r.GetAllResourceTree) req.NewCtxWithGin(c).Handle(r.GetAllResourceTree)
}) })
db.GET(":id", func(c *gin.Context) { db.GET(":id", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(r.GetById) req.NewCtxWithGin(c).Handle(r.GetById)
}) })
saveResource := ctx.NewLogInfo("保存资源").WithSave(true) saveResource := req.NewLogInfo("保存资源").WithSave(true)
srPermission := ctx.NewPermission("resource:add") srPermission := req.NewPermission("resource:add")
db.POST("", func(c *gin.Context) { db.POST("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c). req.NewCtxWithGin(c).
WithLog(saveResource). WithLog(saveResource).
WithRequiredPermission(srPermission). WithRequiredPermission(srPermission).
Handle(r.SaveResource) Handle(r.SaveResource)
}) })
changeStatus := ctx.NewLogInfo("修改资源状态").WithSave(true) changeStatus := req.NewLogInfo("修改资源状态").WithSave(true)
csPermission := ctx.NewPermission("resource:changeStatus") csPermission := req.NewPermission("resource:changeStatus")
db.PUT(":id/:status", func(c *gin.Context) { db.PUT(":id/:status", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c). req.NewCtxWithGin(c).
WithLog(changeStatus). WithLog(changeStatus).
WithRequiredPermission(csPermission). WithRequiredPermission(csPermission).
Handle(r.ChangeStatus) Handle(r.ChangeStatus)
}) })
delResource := ctx.NewLogInfo("删除资源").WithSave(true) delResource := req.NewLogInfo("删除资源").WithSave(true)
dePermission := ctx.NewPermission("resource:delete") dePermission := req.NewPermission("resource:delete")
db.DELETE(":id", func(c *gin.Context) { db.DELETE(":id", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c). req.NewCtxWithGin(c).
WithLog(delResource). WithLog(delResource).
WithRequiredPermission(dePermission). WithRequiredPermission(dePermission).
Handle(r.DelResource) Handle(r.DelResource)

View File

@@ -3,7 +3,7 @@ package router
import ( import (
"mayfly-go/internal/sys/api" "mayfly-go/internal/sys/api"
"mayfly-go/internal/sys/application" "mayfly-go/internal/sys/application"
"mayfly-go/pkg/ctx" "mayfly-go/pkg/req"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@@ -17,37 +17,37 @@ func InitRoleRouter(router *gin.RouterGroup) {
{ {
db.GET("", func(c *gin.Context) { db.GET("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(r.Roles) req.NewCtxWithGin(c).Handle(r.Roles)
}) })
saveRole := ctx.NewLogInfo("保存角色").WithSave(true) saveRole := req.NewLogInfo("保存角色").WithSave(true)
sPermission := ctx.NewPermission("role:add") sPermission := req.NewPermission("role:add")
db.POST("", func(c *gin.Context) { db.POST("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(saveRole). req.NewCtxWithGin(c).WithLog(saveRole).
WithRequiredPermission(sPermission). WithRequiredPermission(sPermission).
Handle(r.SaveRole) Handle(r.SaveRole)
}) })
delRole := ctx.NewLogInfo("删除角色").WithSave(true) delRole := req.NewLogInfo("删除角色").WithSave(true)
drPermission := ctx.NewPermission("role:del") drPermission := req.NewPermission("role:del")
db.DELETE(":id", func(c *gin.Context) { db.DELETE(":id", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(delRole). req.NewCtxWithGin(c).WithLog(delRole).
WithRequiredPermission(drPermission). WithRequiredPermission(drPermission).
Handle(r.DelRole) Handle(r.DelRole)
}) })
db.GET(":id/resourceIds", func(c *gin.Context) { db.GET(":id/resourceIds", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(r.RoleResourceIds) req.NewCtxWithGin(c).Handle(r.RoleResourceIds)
}) })
db.GET(":id/resources", func(c *gin.Context) { db.GET(":id/resources", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(r.RoleResource) req.NewCtxWithGin(c).Handle(r.RoleResource)
}) })
saveResource := ctx.NewLogInfo("保存角色资源").WithSave(true) saveResource := req.NewLogInfo("保存角色资源").WithSave(true)
srPermission := ctx.NewPermission("role:saveResources") srPermission := req.NewPermission("role:saveResources")
db.POST(":id/resources", func(c *gin.Context) { db.POST(":id/resources", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(saveResource). req.NewCtxWithGin(c).WithLog(saveResource).
WithRequiredPermission(srPermission). WithRequiredPermission(srPermission).
Handle(r.SaveResource) Handle(r.SaveResource)
}) })

View File

@@ -3,7 +3,7 @@ package router
import ( import (
"mayfly-go/internal/sys/api" "mayfly-go/internal/sys/api"
"mayfly-go/internal/sys/application" "mayfly-go/internal/sys/application"
"mayfly-go/pkg/ctx" "mayfly-go/pkg/req"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@@ -15,7 +15,7 @@ func InitSyslogRouter(router *gin.RouterGroup) {
sys := router.Group("syslogs") sys := router.Group("syslogs")
{ {
sys.GET("", func(c *gin.Context) { sys.GET("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(s.Syslogs) req.NewCtxWithGin(c).Handle(s.Syslogs)
}) })
} }
} }

View File

@@ -5,15 +5,15 @@ import (
"mayfly-go/internal/tag/api/vo" "mayfly-go/internal/tag/api/vo"
"mayfly-go/internal/tag/application" "mayfly-go/internal/tag/application"
"mayfly-go/internal/tag/domain/entity" "mayfly-go/internal/tag/domain/entity"
"mayfly-go/pkg/ctx"
"mayfly-go/pkg/ginx" "mayfly-go/pkg/ginx"
"mayfly-go/pkg/req"
) )
type TagTree struct { type TagTree struct {
TagTreeApp application.TagTree TagTreeApp application.TagTree
} }
func (p *TagTree) GetAccountTags(rc *ctx.ReqCtx) { func (p *TagTree) GetAccountTags(rc *req.Ctx) {
tagPaths := p.TagTreeApp.ListTagByAccountId(rc.LoginAccount.Id) tagPaths := p.TagTreeApp.ListTagByAccountId(rc.LoginAccount.Id)
allTagPath := make([]string, 0) allTagPath := make([]string, 0)
if len(tagPaths) > 0 { if len(tagPaths) > 0 {
@@ -25,13 +25,13 @@ func (p *TagTree) GetAccountTags(rc *ctx.ReqCtx) {
rc.ResData = allTagPath rc.ResData = allTagPath
} }
func (p *TagTree) GetTagTree(rc *ctx.ReqCtx) { func (p *TagTree) GetTagTree(rc *req.Ctx) {
var tagTrees vo.TagTreeVOS var tagTrees vo.TagTreeVOS
p.TagTreeApp.ListByQuery(new(entity.TagTreeQuery), &tagTrees) p.TagTreeApp.ListByQuery(new(entity.TagTreeQuery), &tagTrees)
rc.ResData = tagTrees.ToTrees(0) rc.ResData = tagTrees.ToTrees(0)
} }
func (p *TagTree) SaveTagTree(rc *ctx.ReqCtx) { func (p *TagTree) SaveTagTree(rc *req.Ctx) {
projectTree := &entity.TagTree{} projectTree := &entity.TagTree{}
ginx.BindJsonAndValid(rc.GinCtx, projectTree) ginx.BindJsonAndValid(rc.GinCtx, projectTree)
@@ -42,6 +42,6 @@ func (p *TagTree) SaveTagTree(rc *ctx.ReqCtx) {
rc.ReqParam = fmt.Sprintf("tagTreeId: %d, tagName: %s, codePath: %s", projectTree.Id, projectTree.Name, projectTree.CodePath) rc.ReqParam = fmt.Sprintf("tagTreeId: %d, tagName: %s, codePath: %s", projectTree.Id, projectTree.Name, projectTree.CodePath)
} }
func (p *TagTree) DelTagTree(rc *ctx.ReqCtx) { func (p *TagTree) DelTagTree(rc *req.Ctx) {
p.TagTreeApp.Delete(uint64(ginx.PathParamInt(rc.GinCtx, "id"))) p.TagTreeApp.Delete(uint64(ginx.PathParamInt(rc.GinCtx, "id")))
} }

View File

@@ -9,8 +9,8 @@ import (
"mayfly-go/internal/tag/application" "mayfly-go/internal/tag/application"
"mayfly-go/internal/tag/domain/entity" "mayfly-go/internal/tag/domain/entity"
"mayfly-go/pkg/biz" "mayfly-go/pkg/biz"
"mayfly-go/pkg/ctx"
"mayfly-go/pkg/ginx" "mayfly-go/pkg/ginx"
"mayfly-go/pkg/req"
"mayfly-go/pkg/utils" "mayfly-go/pkg/utils"
) )
@@ -20,12 +20,12 @@ type Team struct {
AccountApp sys_applicaiton.Account AccountApp sys_applicaiton.Account
} }
func (p *Team) GetTeams(rc *ctx.ReqCtx) { func (p *Team) GetTeams(rc *req.Ctx) {
teams := &[]entity.Team{} teams := &[]entity.Team{}
rc.ResData = p.TeamApp.GetPageList(&entity.Team{}, ginx.GetPageParam(rc.GinCtx), teams) rc.ResData = p.TeamApp.GetPageList(&entity.Team{}, ginx.GetPageParam(rc.GinCtx), teams)
} }
func (p *Team) SaveTeam(rc *ctx.ReqCtx) { func (p *Team) SaveTeam(rc *req.Ctx) {
team := &entity.Team{} team := &entity.Team{}
ginx.BindJsonAndValid(rc.GinCtx, team) ginx.BindJsonAndValid(rc.GinCtx, team)
@@ -47,12 +47,12 @@ func (p *Team) SaveTeam(rc *ctx.ReqCtx) {
} }
} }
func (p *Team) DelTeam(rc *ctx.ReqCtx) { func (p *Team) DelTeam(rc *req.Ctx) {
p.TeamApp.Delete(uint64(ginx.PathParamInt(rc.GinCtx, "id"))) p.TeamApp.Delete(uint64(ginx.PathParamInt(rc.GinCtx, "id")))
} }
// 获取团队的成员信息 // 获取团队的成员信息
func (p *Team) GetTeamMembers(rc *ctx.ReqCtx) { func (p *Team) GetTeamMembers(rc *req.Ctx) {
condition := &entity.TeamMember{TeamId: uint64(ginx.PathParamInt(rc.GinCtx, "id"))} condition := &entity.TeamMember{TeamId: uint64(ginx.PathParamInt(rc.GinCtx, "id"))}
condition.Username = rc.GinCtx.Query("username") condition.Username = rc.GinCtx.Query("username")
@@ -60,7 +60,7 @@ func (p *Team) GetTeamMembers(rc *ctx.ReqCtx) {
} }
// 保存团队信息 // 保存团队信息
func (p *Team) SaveTeamMember(rc *ctx.ReqCtx) { func (p *Team) SaveTeamMember(rc *req.Ctx) {
teamMems := &form.TeamMember{} teamMems := &form.TeamMember{}
ginx.BindJsonAndValid(rc.GinCtx, teamMems) ginx.BindJsonAndValid(rc.GinCtx, teamMems)
@@ -88,7 +88,7 @@ func (p *Team) SaveTeamMember(rc *ctx.ReqCtx) {
} }
// 删除团队成员 // 删除团队成员
func (p *Team) DelTeamMember(rc *ctx.ReqCtx) { func (p *Team) DelTeamMember(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
tid := ginx.PathParamInt(g, "id") tid := ginx.PathParamInt(g, "id")
aid := ginx.PathParamInt(g, "accountId") aid := ginx.PathParamInt(g, "accountId")
@@ -98,12 +98,12 @@ func (p *Team) DelTeamMember(rc *ctx.ReqCtx) {
} }
// 获取团队关联的标签id // 获取团队关联的标签id
func (p *Team) GetTagIds(rc *ctx.ReqCtx) { func (p *Team) GetTagIds(rc *req.Ctx) {
rc.ResData = p.TeamApp.ListTagIds(uint64(ginx.PathParamInt(rc.GinCtx, "id"))) rc.ResData = p.TeamApp.ListTagIds(uint64(ginx.PathParamInt(rc.GinCtx, "id")))
} }
// 保存团队关联标签信息 // 保存团队关联标签信息
func (p *Team) SaveTags(rc *ctx.ReqCtx) { func (p *Team) SaveTags(rc *req.Ctx) {
g := rc.GinCtx g := rc.GinCtx
var form form.TagTreeTeam var form form.TagTreeTeam

View File

@@ -3,7 +3,7 @@ package router
import ( import (
"mayfly-go/internal/tag/api" "mayfly-go/internal/tag/api"
"mayfly-go/internal/tag/application" "mayfly-go/internal/tag/application"
"mayfly-go/pkg/ctx" "mayfly-go/pkg/req"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@@ -17,28 +17,28 @@ func InitTagTreeRouter(router *gin.RouterGroup) {
{ {
// 获取标签树列表 // 获取标签树列表
project.GET("", func(c *gin.Context) { project.GET("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(m.GetTagTree) req.NewCtxWithGin(c).Handle(m.GetTagTree)
}) })
// 获取登录账号拥有的标签信息 // 获取登录账号拥有的标签信息
project.GET("account-has", func(c *gin.Context) { project.GET("account-has", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(m.GetAccountTags) req.NewCtxWithGin(c).Handle(m.GetAccountTags)
}) })
saveProjectTreeLog := ctx.NewLogInfo("标签树-保存信息").WithSave(true) saveProjectTreeLog := req.NewLogInfo("标签树-保存信息").WithSave(true)
savePP := ctx.NewPermission("tag:save") savePP := req.NewPermission("tag:save")
// 保存项目树下的环境信息 // 保存项目树下的环境信息
project.POST("", func(c *gin.Context) { project.POST("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(saveProjectTreeLog). req.NewCtxWithGin(c).WithLog(saveProjectTreeLog).
WithRequiredPermission(savePP). WithRequiredPermission(savePP).
Handle(m.SaveTagTree) Handle(m.SaveTagTree)
}) })
delProjectLog := ctx.NewLogInfo("标签树-删除信息").WithSave(true) delProjectLog := req.NewLogInfo("标签树-删除信息").WithSave(true)
delPP := ctx.NewPermission("tag:del") delPP := req.NewPermission("tag:del")
// 删除标签 // 删除标签
project.DELETE(":id", func(c *gin.Context) { project.DELETE(":id", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(delProjectLog). req.NewCtxWithGin(c).WithLog(delProjectLog).
WithRequiredPermission(delPP). WithRequiredPermission(delPP).
Handle(m.DelTagTree) Handle(m.DelTagTree)
}) })

View File

@@ -4,7 +4,7 @@ import (
sysapp "mayfly-go/internal/sys/application" sysapp "mayfly-go/internal/sys/application"
"mayfly-go/internal/tag/api" "mayfly-go/internal/tag/api"
"mayfly-go/internal/tag/application" "mayfly-go/internal/tag/application"
"mayfly-go/pkg/ctx" "mayfly-go/pkg/req"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@@ -20,59 +20,59 @@ func InitTeamRouter(router *gin.RouterGroup) {
{ {
// 获取团队列表 // 获取团队列表
project.GET("", func(c *gin.Context) { project.GET("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(m.GetTeams) req.NewCtxWithGin(c).Handle(m.GetTeams)
}) })
saveProjectTeamLog := ctx.NewLogInfo("团队-保存信息").WithSave(true) saveProjectTeamLog := req.NewLogInfo("团队-保存信息").WithSave(true)
savePP := ctx.NewPermission("team:save") savePP := req.NewPermission("team:save")
// 保存项目团队信息 // 保存项目团队信息
project.POST("", func(c *gin.Context) { project.POST("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(saveProjectTeamLog). req.NewCtxWithGin(c).WithLog(saveProjectTeamLog).
WithRequiredPermission(savePP). WithRequiredPermission(savePP).
Handle(m.SaveTeam) Handle(m.SaveTeam)
}) })
delProjectTeamLog := ctx.NewLogInfo("团队-删除信息").WithSave(true) delProjectTeamLog := req.NewLogInfo("团队-删除信息").WithSave(true)
delPP := ctx.NewPermission("team:del") delPP := req.NewPermission("team:del")
project.DELETE(":id", func(c *gin.Context) { project.DELETE(":id", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(delProjectTeamLog). req.NewCtxWithGin(c).WithLog(delProjectTeamLog).
WithRequiredPermission(delPP). WithRequiredPermission(delPP).
Handle(m.DelTeam) Handle(m.DelTeam)
}) })
// 获取团队的成员信息列表 // 获取团队的成员信息列表
project.GET("/:id/members", func(c *gin.Context) { project.GET("/:id/members", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(m.GetTeamMembers) req.NewCtxWithGin(c).Handle(m.GetTeamMembers)
}) })
// 保存团队成员 // 保存团队成员
saveProjectTeamMemLog := ctx.NewLogInfo("团队-新增成员").WithSave(true) saveProjectTeamMemLog := req.NewLogInfo("团队-新增成员").WithSave(true)
savePmP := ctx.NewPermission("team:member:save") savePmP := req.NewPermission("team:member:save")
project.POST("/:id/members", func(c *gin.Context) { project.POST("/:id/members", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(saveProjectTeamMemLog). req.NewCtxWithGin(c).WithLog(saveProjectTeamMemLog).
WithRequiredPermission(savePmP). WithRequiredPermission(savePmP).
Handle(m.SaveTeamMember) Handle(m.SaveTeamMember)
}) })
// 删除团队成员 // 删除团队成员
delProjectTeamMemLog := ctx.NewLogInfo("团队-删除成员").WithSave(true) delProjectTeamMemLog := req.NewLogInfo("团队-删除成员").WithSave(true)
savePmdP := ctx.NewPermission("team:member:del") savePmdP := req.NewPermission("team:member:del")
project.DELETE("/:id/members/:accountId", func(c *gin.Context) { project.DELETE("/:id/members/:accountId", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(delProjectTeamMemLog). req.NewCtxWithGin(c).WithLog(delProjectTeamMemLog).
WithRequiredPermission(savePmdP). WithRequiredPermission(savePmdP).
Handle(m.DelTeamMember) Handle(m.DelTeamMember)
}) })
// 获取团队关联的标签id列表 // 获取团队关联的标签id列表
project.GET("/:id/tags", func(c *gin.Context) { project.GET("/:id/tags", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(m.GetTagIds) req.NewCtxWithGin(c).Handle(m.GetTagIds)
}) })
// 保存团队标签关联信息 // 保存团队标签关联信息
saveTeamTagLog := ctx.NewLogInfo("团队-保存标签关联信息").WithSave(true) saveTeamTagLog := req.NewLogInfo("团队-保存标签关联信息").WithSave(true)
saveTeamTagP := ctx.NewPermission("team:tag:save") saveTeamTagP := req.NewPermission("team:tag:save")
project.POST("/:id/tags", func(c *gin.Context) { project.POST("/:id/tags", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c). req.NewCtxWithGin(c).
WithLog(saveTeamTagLog). WithLog(saveTeamTagLog).
WithRequiredPermission(saveTeamTagP). WithRequiredPermission(saveTeamTagP).
Handle(m.SaveTags) Handle(m.SaveTags)

View File

@@ -1,4 +1,4 @@
package ctx package req
import ( import (
"fmt" "fmt"
@@ -11,7 +11,7 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
type SaveLogFunc func(*ReqCtx) type SaveLogFunc func(*Ctx)
var saveLog SaveLogFunc var saveLog SaveLogFunc
@@ -43,7 +43,7 @@ func (i *LogInfo) WithSave(saveLog bool) *LogInfo {
return i return i
} }
func LogHandler(rc *ReqCtx) error { func LogHandler(rc *Ctx) error {
li := rc.LogInfo li := rc.LogInfo
if li == nil { if li == nil {
return nil return nil
@@ -70,7 +70,7 @@ func LogHandler(rc *ReqCtx) error {
return nil return nil
} }
func getLogMsg(rc *ReqCtx) string { func getLogMsg(rc *Ctx) string {
msg := rc.LogInfo.Description + fmt.Sprintf(" ->%dms", rc.timed) msg := rc.LogInfo.Description + fmt.Sprintf(" ->%dms", rc.timed)
if !utils.IsBlank(reflect.ValueOf(rc.ReqParam)) { if !utils.IsBlank(reflect.ValueOf(rc.ReqParam)) {
msg = msg + fmt.Sprintf("\n--> %s", utils.ToString(rc.ReqParam)) msg = msg + fmt.Sprintf("\n--> %s", utils.ToString(rc.ReqParam))
@@ -83,7 +83,7 @@ func getLogMsg(rc *ReqCtx) string {
return msg return msg
} }
func getErrMsg(rc *ReqCtx, err interface{}) string { func getErrMsg(rc *Ctx, err interface{}) string {
msg := rc.LogInfo.Description msg := rc.LogInfo.Description
if !utils.IsBlank(reflect.ValueOf(rc.ReqParam)) { if !utils.IsBlank(reflect.ValueOf(rc.ReqParam)) {
msg = msg + fmt.Sprintf("\n--> %s", utils.ToString(rc.ReqParam)) msg = msg + fmt.Sprintf("\n--> %s", utils.ToString(rc.ReqParam))

View File

@@ -1,4 +1,4 @@
package ctx package req
import ( import (
"encoding/json" "encoding/json"
@@ -29,7 +29,7 @@ var (
permissionCodeRegistry PermissionCodeRegistry permissionCodeRegistry PermissionCodeRegistry
) )
func PermissionHandler(rc *ReqCtx) error { func PermissionHandler(rc *Ctx) error {
if permissionCodeRegistry == nil { if permissionCodeRegistry == nil {
if rediscli.GetCli() == nil { if rediscli.GetCli() == nil {
permissionCodeRegistry = new(DefaultPermissionCodeRegistry) permissionCodeRegistry = new(DefaultPermissionCodeRegistry)

View File

@@ -1,4 +1,4 @@
package ctx package req
import ( import (
"io" "io"
@@ -11,24 +11,24 @@ import (
) )
// 处理函数 // 处理函数
type HandlerFunc func(*ReqCtx) type HandlerFunc func(*Ctx)
type ReqCtx struct { type Ctx struct {
GinCtx *gin.Context // gin context GinCtx *gin.Context // gin context
RequiredPermission *Permission // 需要的权限信息默认为nil需要校验token RequiredPermission *Permission // 需要的权限信息默认为nil需要校验token
LoginAccount *model.LoginAccount // 登录账号信息只有校验token后才会有值 LoginAccount *model.LoginAccount // 登录账号信息只有校验token后才会有值
LogInfo *LogInfo // 日志相关信息 LogInfo *LogInfo // 日志相关信息
ReqParam interface{} // 请求参数,主要用于记录日志 ReqParam any // 请求参数,主要用于记录日志
ResData interface{} // 响应结果 ResData any // 响应结果
Err interface{} // 请求错误 Err any // 请求错误
timed int64 // 执行时间 timed int64 // 执行时间
NoRes bool // 无需返回结果,即文件下载等 NoRes bool // 无需返回结果,即文件下载等
} }
func (rc *ReqCtx) Handle(handler HandlerFunc) { func (rc *Ctx) Handle(handler HandlerFunc) {
ginCtx := rc.GinCtx ginCtx := rc.GinCtx
defer func() { defer func() {
if err := recover(); err != nil { if err := recover(); err != nil {
@@ -41,7 +41,7 @@ func (rc *ReqCtx) Handle(handler HandlerFunc) {
assert.IsTrue(ginCtx != nil, "ginContext == nil") assert.IsTrue(ginCtx != nil, "ginContext == nil")
// 默认为不记录请求参数可在handler回调函数中覆盖赋值 // 默认为不记录请求参数可在handler回调函数中覆盖赋值
rc.ReqParam = 0 rc.ReqParam = nil
// 默认响应结果为nil可在handler中赋值 // 默认响应结果为nil可在handler中赋值
rc.ResData = nil rc.ResData = nil
@@ -59,40 +59,35 @@ func (rc *ReqCtx) Handle(handler HandlerFunc) {
} }
} }
func (rc *ReqCtx) Download(reader io.Reader, filename string) { func (rc *Ctx) Download(reader io.Reader, filename string) {
rc.NoRes = true rc.NoRes = true
ginx.Download(rc.GinCtx, reader, filename) ginx.Download(rc.GinCtx, reader, filename)
} }
// 新建请求上下文默认需要校验token func NewCtxWithGin(g *gin.Context) *Ctx {
func NewReqCtx() *ReqCtx { return &Ctx{GinCtx: g}
return &ReqCtx{}
}
func NewReqCtxWithGin(g *gin.Context) *ReqCtx {
return &ReqCtx{GinCtx: g}
} }
// 调用该方法设置请求描述,则默认记录日志,并不记录响应结果 // 调用该方法设置请求描述,则默认记录日志,并不记录响应结果
func (r *ReqCtx) WithLog(li *LogInfo) *ReqCtx { func (r *Ctx) WithLog(li *LogInfo) *Ctx {
r.LogInfo = li r.LogInfo = li
return r return r
} }
// 设置请求上下文需要的权限信息 // 设置请求上下文需要的权限信息
func (r *ReqCtx) WithRequiredPermission(permission *Permission) *ReqCtx { func (r *Ctx) WithRequiredPermission(permission *Permission) *Ctx {
r.RequiredPermission = permission r.RequiredPermission = permission
return r return r
} }
// 是否需要token // 是否需要token
func (r *ReqCtx) WithNeedToken(needToken bool) *ReqCtx { func (r *Ctx) WithNeedToken(needToken bool) *Ctx {
r.RequiredPermission = &Permission{NeedToken: false} r.RequiredPermission = &Permission{NeedToken: false}
return r return r
} }
// 处理器拦截器函数 // 处理器拦截器函数
type HandlerInterceptorFunc func(*ReqCtx) error type HandlerInterceptorFunc func(*Ctx) error
type HandlerInterceptors []HandlerInterceptorFunc type HandlerInterceptors []HandlerInterceptorFunc
var ( var (
@@ -111,7 +106,7 @@ func UseAfterHandlerInterceptor(b HandlerInterceptorFunc) {
} }
// 应用指定处理器拦截器,如果有一个错误则直接返回错误 // 应用指定处理器拦截器,如果有一个错误则直接返回错误
func ApplyHandlerInterceptor(his HandlerInterceptors, rc *ReqCtx) interface{} { func ApplyHandlerInterceptor(his HandlerInterceptors, rc *Ctx) interface{} {
for _, handler := range his { for _, handler := range his {
if err := handler(rc); err != nil { if err := handler(rc); err != nil {
return err return err

View File

@@ -1,4 +1,4 @@
package ctx package req
import ( import (
"errors" "errors"

View File

@@ -2,8 +2,8 @@ package starter
import ( import (
"mayfly-go/pkg/config" "mayfly-go/pkg/config"
"mayfly-go/pkg/ctx"
"mayfly-go/pkg/logger" "mayfly-go/pkg/logger"
"mayfly-go/pkg/req"
) )
func RunWebServer() { func RunWebServer() {
@@ -12,7 +12,7 @@ func RunWebServer() {
// 初始化日志配置信息 // 初始化日志配置信息
logger.Init() logger.Init()
// 初始化jwt key与expire time等 // 初始化jwt key与expire time等
ctx.InitTokenConfig() req.InitTokenConfig()
// 打印banner // 打印banner
printBanner() printBanner()

View File

@@ -4,17 +4,17 @@ import (
"mayfly-go/initialize" "mayfly-go/initialize"
"mayfly-go/pkg/biz" "mayfly-go/pkg/biz"
"mayfly-go/pkg/config" "mayfly-go/pkg/config"
"mayfly-go/pkg/ctx"
"mayfly-go/pkg/global" "mayfly-go/pkg/global"
"mayfly-go/pkg/req"
) )
func runWebServer() { func runWebServer() {
// 权限处理器 // 权限处理器
ctx.UseBeforeHandlerInterceptor(ctx.PermissionHandler) req.UseBeforeHandlerInterceptor(req.PermissionHandler)
// 日志处理器 // 日志处理器
ctx.UseAfterHandlerInterceptor(ctx.LogHandler) req.UseAfterHandlerInterceptor(req.LogHandler)
// 设置日志保存函数 // 设置日志保存函数
ctx.SetSaveLogFunc(initialize.InitSaveLogFunc()) req.SetSaveLogFunc(initialize.InitSaveLogFunc())
// 注册路由 // 注册路由
web := initialize.InitRouter() web := initialize.InitRouter()