mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-12-15 12:16:34 +08:00
refactor: 后端路由定义方式&请求参数绑定重构
This commit is contained in:
@@ -479,7 +479,7 @@ const search = async () => {
|
|||||||
pageTableRef.value.loading(true);
|
pageTableRef.value.loading(true);
|
||||||
let res: any = await dbApi.dbs.request(state.query);
|
let res: any = await dbApi.dbs.request(state.query);
|
||||||
// 切割数据库
|
// 切割数据库
|
||||||
res.list.forEach((e: any) => {
|
res.list?.forEach((e: any) => {
|
||||||
e.popoverSelectDbVisible = false;
|
e.popoverSelectDbVisible = false;
|
||||||
e.dbs = e.database.split(' ');
|
e.dbs = e.database.split(' ');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -269,9 +269,9 @@ const deleteTeam = () => {
|
|||||||
|
|
||||||
const showMembers = async (team: any) => {
|
const showMembers = async (team: any) => {
|
||||||
state.showMemDialog.query.teamId = team.id;
|
state.showMemDialog.query.teamId = team.id;
|
||||||
|
state.showMemDialog.visible = true;
|
||||||
await setMemebers();
|
await setMemebers();
|
||||||
state.showMemDialog.title = `[${team.name}] 成员信息`;
|
state.showMemDialog.title = `[${team.name}] 成员信息`;
|
||||||
state.showMemDialog.visible = true;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const getAccount = (username: any) => {
|
const getAccount = (username: any) => {
|
||||||
|
|||||||
@@ -12,10 +12,6 @@ func InitCommonRouter(router *gin.RouterGroup) {
|
|||||||
c := &api.Common{}
|
c := &api.Common{}
|
||||||
{
|
{
|
||||||
// 获取公钥
|
// 获取公钥
|
||||||
common.GET("public-key", func(g *gin.Context) {
|
req.NewGet("public-key", c.RasPublicKey).DontNeedToken().Group(common)
|
||||||
req.NewCtxWithGin(g).
|
|
||||||
DontNeedToken().
|
|
||||||
Handle(c.RasPublicKey)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,9 +23,6 @@ func InitIndexRouter(router *gin.RouterGroup) {
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
// 首页基本信息统计
|
// 首页基本信息统计
|
||||||
index.GET("count", func(g *gin.Context) {
|
req.NewGet("count", i.Count).Group(index)
|
||||||
req.NewCtxWithGin(g).
|
|
||||||
Handle(i.Count)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,8 +35,7 @@ const DEFAULT_ROW_SIZE = 5000
|
|||||||
|
|
||||||
// @router /api/dbs [get]
|
// @router /api/dbs [get]
|
||||||
func (d *Db) Dbs(rc *req.Ctx) {
|
func (d *Db) Dbs(rc *req.Ctx) {
|
||||||
condition := new(entity.DbQuery)
|
queryCond, page := ginx.BindQueryAndPage[*entity.DbQuery](rc.GinCtx, new(entity.DbQuery))
|
||||||
condition.TagPathLike = rc.GinCtx.Query("tagPath")
|
|
||||||
|
|
||||||
// 不存在可访问标签id,即没有可操作数据
|
// 不存在可访问标签id,即没有可操作数据
|
||||||
tagIds := d.TagApp.ListTagIdByAccountId(rc.LoginAccount.Id)
|
tagIds := d.TagApp.ListTagIdByAccountId(rc.LoginAccount.Id)
|
||||||
@@ -44,16 +43,14 @@ func (d *Db) Dbs(rc *req.Ctx) {
|
|||||||
rc.ResData = model.EmptyPageResult[any]()
|
rc.ResData = model.EmptyPageResult[any]()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
condition.TagIds = tagIds
|
|
||||||
rc.ResData = d.DbApp.GetPageList(condition, ginx.GetPageParam(rc.GinCtx), new([]vo.SelectDataDbVO))
|
queryCond.TagIds = tagIds
|
||||||
|
rc.ResData = d.DbApp.GetPageList(queryCond, page, new([]vo.SelectDataDbVO))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Db) Save(rc *req.Ctx) {
|
func (d *Db) Save(rc *req.Ctx) {
|
||||||
form := &form.DbForm{}
|
form := &form.DbForm{}
|
||||||
ginx.BindJsonAndValid(rc.GinCtx, form)
|
db := ginx.BindJsonAndCopyTo[*entity.Db](rc.GinCtx, form, new(entity.Db))
|
||||||
|
|
||||||
db := new(entity.Db)
|
|
||||||
utils.Copy(db, form)
|
|
||||||
|
|
||||||
// 密码解密,并使用解密后的赋值
|
// 密码解密,并使用解密后的赋值
|
||||||
originPwd, err := utils.DefaultRsaDecrypt(form.Password, true)
|
originPwd, err := utils.DefaultRsaDecrypt(form.Password, true)
|
||||||
@@ -319,7 +316,6 @@ func (d *Db) DumpSql(rc *req.Ctx) {
|
|||||||
|
|
||||||
writer.WriteString("COMMIT;\n")
|
writer.WriteString("COMMIT;\n")
|
||||||
}
|
}
|
||||||
rc.NoRes = true
|
|
||||||
|
|
||||||
rc.ReqParam = fmt.Sprintf("%s, tables: %s, dumpType: %s", dbInstance.Info.GetLogDesc(), tablesStr, dumpType)
|
rc.ReqParam = fmt.Sprintf("%s, tables: %s, dumpType: %s", dbInstance.Info.GetLogDesc(), tablesStr, dumpType)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,12 +12,7 @@ type DbSqlExec struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *DbSqlExec) DbSqlExecs(rc *req.Ctx) {
|
func (d *DbSqlExec) DbSqlExecs(rc *req.Ctx) {
|
||||||
g := rc.GinCtx
|
queryCond, page := ginx.BindQueryAndPage(rc.GinCtx, new(entity.DbSqlExecQuery))
|
||||||
m := &entity.DbSqlExec{DbId: uint64(ginx.QueryInt(g, "dbId", 0)),
|
queryCond.CreatorId = rc.LoginAccount.Id
|
||||||
Db: g.Query("db"),
|
rc.ResData = d.DbSqlExecApp.GetPageList(queryCond, page, new([]entity.DbSqlExec))
|
||||||
Table: g.Query("table"),
|
|
||||||
Type: int8(ginx.QueryInt(g, "type", 0)),
|
|
||||||
}
|
|
||||||
m.CreatorId = rc.LoginAccount.Id
|
|
||||||
rc.ResData = d.DbSqlExecApp.GetPageList(m, ginx.GetPageParam(rc.GinCtx), new([]entity.DbSqlExec))
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ type DbSqlExec interface {
|
|||||||
DeleteBy(condition *entity.DbSqlExec)
|
DeleteBy(condition *entity.DbSqlExec)
|
||||||
|
|
||||||
// 分页获取
|
// 分页获取
|
||||||
GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
GetPageList(condition *entity.DbSqlExecQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDbSqlExecApp(dbExecSqlRepo repository.DbSqlExec) DbSqlExec {
|
func newDbSqlExecApp(dbExecSqlRepo repository.DbSqlExec) DbSqlExec {
|
||||||
@@ -152,7 +152,7 @@ func (d *dbSqlExecAppImpl) DeleteBy(condition *entity.DbSqlExec) {
|
|||||||
d.dbSqlExecRepo.DeleteBy(condition)
|
d.dbSqlExecRepo.DeleteBy(condition)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dbSqlExecAppImpl) GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
func (d *dbSqlExecAppImpl) GetPageList(condition *entity.DbSqlExecQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||||
return d.dbSqlExecRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
return d.dbSqlExecRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,8 +16,17 @@ type DbQuery struct {
|
|||||||
Database string `orm:"column(database)" json:"database"`
|
Database string `orm:"column(database)" json:"database"`
|
||||||
Params string `json:"params"`
|
Params string `json:"params"`
|
||||||
Remark string `json:"remark"`
|
Remark string `json:"remark"`
|
||||||
TagId uint64
|
|
||||||
|
|
||||||
TagIds []uint64
|
TagIds []uint64
|
||||||
TagPathLike string
|
TagPath string `form:"tagPath"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DbSqlExecQuery struct {
|
||||||
|
Id uint64 `json:"id" form:"id"`
|
||||||
|
DbId uint64 `json:"dbId" form:"dbId"`
|
||||||
|
Db string `json:"db" form:"db"`
|
||||||
|
Table string `json:"table" form:"table"`
|
||||||
|
Type int8 `json:"type" form:"type"` // 类型
|
||||||
|
|
||||||
|
CreatorId uint64
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ type DbSqlExec interface {
|
|||||||
DeleteBy(condition *entity.DbSqlExec)
|
DeleteBy(condition *entity.DbSqlExec)
|
||||||
|
|
||||||
// 分页获取
|
// 分页获取
|
||||||
GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
GetPageList(condition *entity.DbSqlExecQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ func (d *dbRepoImpl) GetDbList(condition *entity.DbQuery, pageParam *model.PageP
|
|||||||
Like("host", condition.Host).
|
Like("host", condition.Host).
|
||||||
Like("database", condition.Database).
|
Like("database", condition.Database).
|
||||||
In("tag_id", condition.TagIds).
|
In("tag_id", condition.TagIds).
|
||||||
RLike("tag_path", condition.TagPathLike).
|
RLike("tag_path", condition.TagPath).
|
||||||
OrderByAsc("tag_path")
|
OrderByAsc("tag_path")
|
||||||
return gormx.PageQuery(qd, pageParam, toEntity)
|
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||||
}
|
}
|
||||||
@@ -30,9 +30,6 @@ func (d *dbRepoImpl) Count(condition *entity.DbQuery) int64 {
|
|||||||
if len(condition.TagIds) > 0 {
|
if len(condition.TagIds) > 0 {
|
||||||
where["tag_id"] = condition.TagIds
|
where["tag_id"] = condition.TagIds
|
||||||
}
|
}
|
||||||
if condition.TagId != 0 {
|
|
||||||
where["tag_id"] = condition.TagId
|
|
||||||
}
|
|
||||||
return gormx.CountByCond(new(entity.Db), where)
|
return gormx.CountByCond(new(entity.Db), where)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func (d *dbSqlExecRepoImpl) DeleteBy(condition *entity.DbSqlExec) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 分页获取
|
// 分页获取
|
||||||
func (d *dbSqlExecRepoImpl) GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
func (d *dbSqlExecRepoImpl) GetPageList(condition *entity.DbSqlExecQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||||
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
|
qd := gormx.NewQuery(new(entity.DbSqlExec)).WithCondModel(condition).WithOrderBy(orderBy...)
|
||||||
return gormx.PageQuery(qd, pageParam, toEntity)
|
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,103 +12,55 @@ import (
|
|||||||
|
|
||||||
func InitDbRouter(router *gin.RouterGroup) {
|
func InitDbRouter(router *gin.RouterGroup) {
|
||||||
db := router.Group("dbs")
|
db := router.Group("dbs")
|
||||||
{
|
|
||||||
d := &api.Db{
|
|
||||||
DbApp: application.GetDbApp(),
|
|
||||||
DbSqlExecApp: application.GetDbSqlExecApp(),
|
|
||||||
MsgApp: msgapp.GetMsgApp(),
|
|
||||||
TagApp: tagapp.GetTagTreeApp(),
|
|
||||||
}
|
|
||||||
// 获取所有数据库列表
|
|
||||||
db.GET("", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).Handle(d.Dbs)
|
|
||||||
})
|
|
||||||
|
|
||||||
saveDb := req.NewLogInfo("db-保存数据库信息").WithSave(true)
|
d := &api.Db{
|
||||||
db.POST("", func(c *gin.Context) {
|
DbApp: application.GetDbApp(),
|
||||||
req.NewCtxWithGin(c).
|
DbSqlExecApp: application.GetDbSqlExecApp(),
|
||||||
WithLog(saveDb).
|
MsgApp: msgapp.GetMsgApp(),
|
||||||
Handle(d.Save)
|
TagApp: tagapp.GetTagTreeApp(),
|
||||||
})
|
}
|
||||||
|
|
||||||
|
reqs := [...]*req.Conf{
|
||||||
|
// 获取数据库列表
|
||||||
|
req.NewGet("", d.Dbs),
|
||||||
|
|
||||||
|
req.NewPost("", d.Save).Log(req.NewLogSave("db-保存数据库信息")),
|
||||||
|
|
||||||
// 获取数据库实例的所有数据库名
|
// 获取数据库实例的所有数据库名
|
||||||
db.POST("databases", func(c *gin.Context) {
|
req.NewGet("/databases", d.GetDatabaseNames),
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
Handle(d.GetDatabaseNames)
|
|
||||||
})
|
|
||||||
|
|
||||||
db.GET(":dbId/pwd", func(c *gin.Context) {
|
req.NewGet(":dbId/pwd", d.GetDbPwd),
|
||||||
req.NewCtxWithGin(c).Handle(d.GetDbPwd)
|
|
||||||
})
|
|
||||||
|
|
||||||
deleteDb := req.NewLogInfo("db-删除数据库信息").WithSave(true)
|
req.NewDelete(":dbId", d.DeleteDb).Log(req.NewLogSave("db-删除数据库信息")),
|
||||||
db.DELETE(":dbId", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithLog(deleteDb).
|
|
||||||
Handle(d.DeleteDb)
|
|
||||||
})
|
|
||||||
|
|
||||||
db.GET(":dbId/t-infos", func(c *gin.Context) {
|
req.NewGet(":dbId/t-infos", d.TableInfos),
|
||||||
req.NewCtxWithGin(c).Handle(d.TableInfos)
|
|
||||||
})
|
|
||||||
|
|
||||||
db.GET(":dbId/t-index", func(c *gin.Context) {
|
req.NewGet(":dbId/t-index", d.TableIndex),
|
||||||
req.NewCtxWithGin(c).Handle(d.TableIndex)
|
|
||||||
})
|
|
||||||
|
|
||||||
db.GET(":dbId/t-create-ddl", func(c *gin.Context) {
|
req.NewGet(":dbId/t-create-ddl", d.GetCreateTableDdl),
|
||||||
req.NewCtxWithGin(c).Handle(d.GetCreateTableDdl)
|
|
||||||
})
|
|
||||||
|
|
||||||
execSqlLog := req.NewLogInfo("db-执行Sql")
|
req.NewPost(":dbId/exec-sql", d.ExecSql).Log(req.NewLog("db-执行Sql")),
|
||||||
db.POST(":dbId/exec-sql", func(g *gin.Context) {
|
|
||||||
rc := req.NewCtxWithGin(g).WithLog(execSqlLog)
|
|
||||||
rc.Handle(d.ExecSql)
|
|
||||||
})
|
|
||||||
|
|
||||||
execSqlFileLog := req.NewLogInfo("db-执行Sql文件").WithSave(true)
|
req.NewPost(":dbId/exec-sql-file", d.ExecSqlFile).Log(req.NewLogSave("db-执行Sql文件")),
|
||||||
db.POST(":dbId/exec-sql-file", func(g *gin.Context) {
|
|
||||||
req.NewCtxWithGin(g).
|
|
||||||
WithLog(execSqlFileLog).
|
|
||||||
Handle(d.ExecSqlFile)
|
|
||||||
})
|
|
||||||
|
|
||||||
dumpLog := req.NewLogInfo("db-导出sql文件").WithSave(true)
|
req.NewGet(":dbId/dump", d.DumpSql).Log(req.NewLogSave("db-导出sql文件")).NoRes(),
|
||||||
db.GET(":dbId/dump", func(g *gin.Context) {
|
|
||||||
req.NewCtxWithGin(g).
|
|
||||||
WithLog(dumpLog).
|
|
||||||
Handle(d.DumpSql)
|
|
||||||
})
|
|
||||||
|
|
||||||
db.GET(":dbId/t-metadata", func(c *gin.Context) {
|
req.NewGet(":dbId/t-metadata", d.TableMA),
|
||||||
req.NewCtxWithGin(c).Handle(d.TableMA)
|
|
||||||
})
|
|
||||||
|
|
||||||
db.GET(":dbId/c-metadata", func(c *gin.Context) {
|
req.NewGet(":dbId/c-metadata", d.ColumnMA),
|
||||||
req.NewCtxWithGin(c).Handle(d.ColumnMA)
|
|
||||||
})
|
|
||||||
|
|
||||||
db.GET(":dbId/hint-tables", func(c *gin.Context) {
|
req.NewGet(":dbId/hint-tables", d.HintTables),
|
||||||
req.NewCtxWithGin(c).Handle(d.HintTables)
|
|
||||||
})
|
|
||||||
|
|
||||||
/** db sql相关接口 */
|
// 用户sql相关
|
||||||
|
req.NewPost(":dbId/sql", d.SaveSql),
|
||||||
|
|
||||||
db.POST(":dbId/sql", func(c *gin.Context) {
|
req.NewGet(":dbId/sql", d.GetSql),
|
||||||
rc := req.NewCtxWithGin(c)
|
|
||||||
rc.Handle(d.SaveSql)
|
|
||||||
})
|
|
||||||
|
|
||||||
db.GET(":dbId/sql", func(c *gin.Context) {
|
req.NewDelete(":dbId/sql", d.DeleteSql),
|
||||||
req.NewCtxWithGin(c).Handle(d.GetSql)
|
|
||||||
})
|
|
||||||
|
|
||||||
db.DELETE(":dbId/sql", func(c *gin.Context) {
|
req.NewGet(":dbId/sql-names", d.GetSqlNames),
|
||||||
req.NewCtxWithGin(c).Handle(d.DeleteSql)
|
|
||||||
})
|
|
||||||
|
|
||||||
db.GET(":dbId/sql-names", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).Handle(d.GetSqlNames)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
req.BatchSetGroup(db, reqs[:])
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,14 +10,12 @@ import (
|
|||||||
|
|
||||||
func InitDbSqlExecRouter(router *gin.RouterGroup) {
|
func InitDbSqlExecRouter(router *gin.RouterGroup) {
|
||||||
db := router.Group("/dbs/:dbId/sql-execs")
|
db := router.Group("/dbs/:dbId/sql-execs")
|
||||||
{
|
|
||||||
d := &api.DbSqlExec{
|
d := &api.DbSqlExec{
|
||||||
DbSqlExecApp: application.GetDbSqlExecApp(),
|
DbSqlExecApp: application.GetDbSqlExecApp(),
|
||||||
}
|
|
||||||
// 获取所有数据库sql执行记录列表
|
|
||||||
db.GET("", func(c *gin.Context) {
|
|
||||||
rc := req.NewCtxWithGin(c)
|
|
||||||
rc.Handle(d.DbSqlExecs)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取所有数据库sql执行记录列表
|
||||||
|
req.NewGet("", d.DbSqlExecs).Group(db)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,25 +18,15 @@ type AuthCert struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ac *AuthCert) BaseAuthCerts(rc *req.Ctx) {
|
func (ac *AuthCert) BaseAuthCerts(rc *req.Ctx) {
|
||||||
g := rc.GinCtx
|
queryCond, page := ginx.BindQueryAndPage(rc.GinCtx, new(entity.AuthCertQuery))
|
||||||
condition := &entity.AuthCert{
|
rc.ResData = ac.AuthCertApp.GetPageList(queryCond, page, new([]vo.AuthCertBaseVO))
|
||||||
Name: g.Query("name"),
|
|
||||||
AuthMethod: int8(ginx.QueryInt(g, "authMethod", 0)),
|
|
||||||
}
|
|
||||||
condition.Id = uint64(ginx.QueryInt(g, "id", 0))
|
|
||||||
rc.ResData = ac.AuthCertApp.GetPageList(condition, ginx.GetPageParam(g), new([]vo.AuthCertBaseVO))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ac *AuthCert) AuthCerts(rc *req.Ctx) {
|
func (ac *AuthCert) AuthCerts(rc *req.Ctx) {
|
||||||
g := rc.GinCtx
|
queryCond, page := ginx.BindQueryAndPage(rc.GinCtx, new(entity.AuthCertQuery))
|
||||||
condition := &entity.AuthCert{
|
|
||||||
Name: g.Query("name"),
|
|
||||||
AuthMethod: int8(ginx.QueryInt(g, "authMethod", 0)),
|
|
||||||
}
|
|
||||||
condition.Id = uint64(ginx.QueryInt(g, "id", 0))
|
|
||||||
|
|
||||||
res := new([]*entity.AuthCert)
|
res := new([]*entity.AuthCert)
|
||||||
pageRes := ac.AuthCertApp.GetPageList(condition, ginx.GetPageParam(g), res)
|
pageRes := ac.AuthCertApp.GetPageList(queryCond, page, res)
|
||||||
for _, r := range *res {
|
for _, r := range *res {
|
||||||
r.PwdDecrypt()
|
r.PwdDecrypt()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,10 +33,7 @@ type Machine struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Machine) Machines(rc *req.Ctx) {
|
func (m *Machine) Machines(rc *req.Ctx) {
|
||||||
condition := new(entity.MachineQuery)
|
condition, pageParam := ginx.BindQueryAndPage(rc.GinCtx, new(entity.MachineQuery))
|
||||||
condition.Ip = rc.GinCtx.Query("ip")
|
|
||||||
condition.Name = rc.GinCtx.Query("name")
|
|
||||||
condition.TagPathLike = rc.GinCtx.Query("tagPath")
|
|
||||||
|
|
||||||
// 不存在可访问标签id,即没有可操作数据
|
// 不存在可访问标签id,即没有可操作数据
|
||||||
tagIds := m.TagApp.ListTagIdByAccountId(rc.LoginAccount.Id)
|
tagIds := m.TagApp.ListTagIdByAccountId(rc.LoginAccount.Id)
|
||||||
@@ -46,7 +43,7 @@ func (m *Machine) Machines(rc *req.Ctx) {
|
|||||||
}
|
}
|
||||||
condition.TagIds = tagIds
|
condition.TagIds = tagIds
|
||||||
|
|
||||||
res := m.MachineApp.GetMachineList(condition, ginx.GetPageParam(rc.GinCtx), new([]*vo.MachineVO))
|
res := m.MachineApp.GetMachineList(condition, pageParam, new([]*vo.MachineVO))
|
||||||
if res.Total == 0 {
|
if res.Total == 0 {
|
||||||
rc.ResData = res
|
rc.ResData = res
|
||||||
return
|
return
|
||||||
@@ -65,12 +62,8 @@ func (m *Machine) MachineStats(rc *req.Ctx) {
|
|||||||
|
|
||||||
// 保存机器信息
|
// 保存机器信息
|
||||||
func (m *Machine) SaveMachine(rc *req.Ctx) {
|
func (m *Machine) SaveMachine(rc *req.Ctx) {
|
||||||
g := rc.GinCtx
|
|
||||||
machineForm := new(form.MachineForm)
|
machineForm := new(form.MachineForm)
|
||||||
ginx.BindJsonAndValid(g, machineForm)
|
me := ginx.BindJsonAndCopyTo(rc.GinCtx, machineForm, new(entity.Machine))
|
||||||
|
|
||||||
me := new(entity.Machine)
|
|
||||||
utils.Copy(me, machineForm)
|
|
||||||
|
|
||||||
machineForm.Password = "******"
|
machineForm.Password = "******"
|
||||||
rc.ReqParam = machineForm
|
rc.ReqParam = machineForm
|
||||||
@@ -199,7 +192,7 @@ 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(req.NewLogInfo("机器-终端操作").WithSave(true))
|
rc.WithLog(req.NewLogSave("机器-终端操作"))
|
||||||
rc.ReqParam = cli.GetMachine().GetLogDesc()
|
rc.ReqParam = cli.GetMachine().GetLogDesc()
|
||||||
req.LogHandler(rc)
|
req.LogHandler(rc)
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import (
|
|||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
"mayfly-go/pkg/ginx"
|
"mayfly-go/pkg/ginx"
|
||||||
"mayfly-go/pkg/req"
|
"mayfly-go/pkg/req"
|
||||||
"mayfly-go/pkg/utils"
|
|
||||||
"mayfly-go/pkg/ws"
|
"mayfly-go/pkg/ws"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -40,22 +39,16 @@ func (m *MachineFile) MachineFiles(rc *req.Ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *MachineFile) SaveMachineFiles(rc *req.Ctx) {
|
func (m *MachineFile) SaveMachineFiles(rc *req.Ctx) {
|
||||||
g := rc.GinCtx
|
|
||||||
fileForm := new(form.MachineFileForm)
|
fileForm := new(form.MachineFileForm)
|
||||||
ginx.BindJsonAndValid(g, fileForm)
|
entity := ginx.BindJsonAndCopyTo[*entity.MachineFile](rc.GinCtx, fileForm, new(entity.MachineFile))
|
||||||
|
|
||||||
entity := new(entity.MachineFile)
|
|
||||||
utils.Copy(entity, fileForm)
|
|
||||||
|
|
||||||
entity.SetBaseInfo(rc.LoginAccount)
|
entity.SetBaseInfo(rc.LoginAccount)
|
||||||
|
|
||||||
|
rc.ReqParam = fileForm
|
||||||
m.MachineFileApp.Save(entity)
|
m.MachineFileApp.Save(entity)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MachineFile) DeleteFile(rc *req.Ctx) {
|
func (m *MachineFile) DeleteFile(rc *req.Ctx) {
|
||||||
g := rc.GinCtx
|
m.MachineFileApp.Delete(GetMachineFileId(rc.GinCtx))
|
||||||
fid := GetMachineFileId(g)
|
|
||||||
m.MachineFileApp.Delete(fid)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** sftp相关操作 */
|
/*** sftp相关操作 */
|
||||||
@@ -64,8 +57,7 @@ func (m *MachineFile) CreateFile(rc *req.Ctx) {
|
|||||||
g := rc.GinCtx
|
g := rc.GinCtx
|
||||||
fid := GetMachineFileId(g)
|
fid := GetMachineFileId(g)
|
||||||
|
|
||||||
form := new(form.MachineCreateFileForm)
|
form := ginx.BindJsonAndValid(g, new(form.MachineCreateFileForm))
|
||||||
ginx.BindJsonAndValid(g, form)
|
|
||||||
path := form.Path
|
path := form.Path
|
||||||
|
|
||||||
mi := m.MachineFileApp.GetMachine(fid)
|
mi := m.MachineFileApp.GetMachine(fid)
|
||||||
|
|||||||
@@ -31,12 +31,9 @@ func (m *MachineScript) MachineScripts(rc *req.Ctx) {
|
|||||||
|
|
||||||
func (m *MachineScript) SaveMachineScript(rc *req.Ctx) {
|
func (m *MachineScript) SaveMachineScript(rc *req.Ctx) {
|
||||||
form := new(form.MachineScriptForm)
|
form := new(form.MachineScriptForm)
|
||||||
ginx.BindJsonAndValid(rc.GinCtx, form)
|
machineScript := ginx.BindJsonAndCopyTo(rc.GinCtx, form, new(entity.MachineScript))
|
||||||
rc.ReqParam = form
|
|
||||||
|
|
||||||
// 转换为entity,并设置基本信息
|
rc.ReqParam = form
|
||||||
machineScript := new(entity.MachineScript)
|
|
||||||
utils.Copy(machineScript, form)
|
|
||||||
machineScript.SetBaseInfo(rc.LoginAccount)
|
machineScript.SetBaseInfo(rc.LoginAccount)
|
||||||
|
|
||||||
m.MachineScriptApp.Save(machineScript)
|
m.MachineScriptApp.Save(machineScript)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type AuthCert interface {
|
type AuthCert interface {
|
||||||
GetPageList(condition *entity.AuthCert, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
GetPageList(condition *entity.AuthCertQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||||
|
|
||||||
Save(ac *entity.AuthCert)
|
Save(ac *entity.AuthCert)
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ type authCertAppImpl struct {
|
|||||||
authCertRepo repository.AuthCert
|
authCertRepo repository.AuthCert
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *authCertAppImpl) GetPageList(condition *entity.AuthCert, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
func (a *authCertAppImpl) GetPageList(condition *entity.AuthCertQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||||
return a.authCertRepo.GetPageList(condition, pageParam, toEntity)
|
return a.authCertRepo.GetPageList(condition, pageParam, toEntity)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,14 @@
|
|||||||
package entity
|
package entity
|
||||||
|
|
||||||
import "mayfly-go/pkg/model"
|
|
||||||
|
|
||||||
type MachineQuery struct {
|
type MachineQuery struct {
|
||||||
model.Model
|
Name string `json:"name" form:"name"`
|
||||||
Name string `json:"name"`
|
Ip string `json:"ip" form:"ip"` // IP地址
|
||||||
Ip string `json:"ip"` // IP地址
|
TagPath string `json:"tagPath" form:"tagPath"`
|
||||||
Username string `json:"username"` // 用户名
|
TagIds []uint64
|
||||||
AuthMethod int8 `json:"authMethod"` // 授权认证方式
|
}
|
||||||
Password string `json:"-"`
|
|
||||||
Port int `json:"port"` // 端口号
|
type AuthCertQuery struct {
|
||||||
Status int8 `json:"status"` // 状态 1:启用;2:停用
|
Id uint64 `json:"id" form:"id"`
|
||||||
Remark string `json:"remark"` // 备注
|
Name string `json:"name" form:"name"`
|
||||||
SshTunnelMachineId uint64 `json:"sshTunnelMachineId"` // ssh隧道机器id
|
AuthMethod string `json:"authMethod" form:"authMethod"` // IP地址
|
||||||
EnableRecorder int8 `json:"enableRecorder"` // 是否启用终端回放记录
|
|
||||||
|
|
||||||
TagId uint64
|
|
||||||
TagPathLike string
|
|
||||||
TagIds []uint64
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type AuthCert interface {
|
type AuthCert interface {
|
||||||
GetPageList(condition *entity.AuthCert, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
GetPageList(condition *entity.AuthCertQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||||
|
|
||||||
Insert(ac *entity.AuthCert)
|
Insert(ac *entity.AuthCert)
|
||||||
|
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ func newAuthCertRepo() repository.AuthCert {
|
|||||||
return new(authCertRepoImpl)
|
return new(authCertRepoImpl)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *authCertRepoImpl) GetPageList(condition *entity.AuthCert, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
func (m *authCertRepoImpl) GetPageList(condition *entity.AuthCertQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||||
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
|
qd := gormx.NewQuery(new(entity.AuthCert)).WithCondModel(condition).WithOrderBy(orderBy...)
|
||||||
return gormx.PageQuery(qd, pageParam, toEntity)
|
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ func (m *machineRepoImpl) GetMachineList(condition *entity.MachineQuery, pagePar
|
|||||||
Like("ip", condition.Ip).
|
Like("ip", condition.Ip).
|
||||||
Like("name", condition.Name).
|
Like("name", condition.Name).
|
||||||
In("tag_id", condition.TagIds).
|
In("tag_id", condition.TagIds).
|
||||||
RLike("tag_path", condition.TagPathLike).
|
RLike("tag_path", condition.TagPath).
|
||||||
OrderByAsc("tag_path")
|
OrderByAsc("tag_path")
|
||||||
return gormx.PageQuery(qd, pageParam, toEntity)
|
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||||
}
|
}
|
||||||
@@ -31,9 +31,6 @@ func (m *machineRepoImpl) Count(condition *entity.MachineQuery) int64 {
|
|||||||
if len(condition.TagIds) > 0 {
|
if len(condition.TagIds) > 0 {
|
||||||
where["tag_id"] = condition.TagIds
|
where["tag_id"] = condition.TagIds
|
||||||
}
|
}
|
||||||
if condition.TagId != 0 {
|
|
||||||
where["tag_id"] = condition.TagId
|
|
||||||
}
|
|
||||||
|
|
||||||
return gormx.CountByCond(new(entity.Machine), where)
|
return gormx.CountByCond(new(entity.Machine), where)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,36 +10,19 @@ import (
|
|||||||
|
|
||||||
func InitAuthCertRouter(router *gin.RouterGroup) {
|
func InitAuthCertRouter(router *gin.RouterGroup) {
|
||||||
r := &api.AuthCert{AuthCertApp: application.GetAuthCertApp()}
|
r := &api.AuthCert{AuthCertApp: application.GetAuthCertApp()}
|
||||||
db := router.Group("sys/authcerts")
|
|
||||||
{
|
ag := router.Group("sys/authcerts")
|
||||||
listAcP := req.NewPermission("authcert")
|
|
||||||
db.GET("", func(c *gin.Context) {
|
reqs := [...]*req.Conf{
|
||||||
req.NewCtxWithGin(c).
|
req.NewGet("", r.AuthCerts).RequiredPermissionCode("authcert"),
|
||||||
WithRequiredPermission(listAcP).
|
|
||||||
Handle(r.AuthCerts)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 基础授权凭证信息,不包含密码等
|
// 基础授权凭证信息,不包含密码等
|
||||||
db.GET("base", func(c *gin.Context) {
|
req.NewGet("base", r.BaseAuthCerts),
|
||||||
req.NewCtxWithGin(c).Handle(r.BaseAuthCerts)
|
|
||||||
})
|
|
||||||
|
|
||||||
saveAc := req.NewLogInfo("保存授权凭证").WithSave(true)
|
req.NewPost("", r.SaveAuthCert).Log(req.NewLogSave("保存授权凭证")).RequiredPermissionCode("authcert:save"),
|
||||||
saveAcP := req.NewPermission("authcert:save")
|
|
||||||
db.POST("", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithLog(saveAc).
|
|
||||||
WithRequiredPermission(saveAcP).
|
|
||||||
Handle(r.SaveAuthCert)
|
|
||||||
})
|
|
||||||
|
|
||||||
deleteAc := req.NewLogInfo("删除授权凭证").WithSave(true)
|
req.NewDelete(":id", r.Delete).Log(req.NewLogSave("删除授权凭证")).RequiredPermissionCode("authcert:del"),
|
||||||
deleteAcP := req.NewPermission("authcert:del")
|
|
||||||
db.DELETE(":id", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithLog(deleteAc).
|
|
||||||
WithRequiredPermission(deleteAcP).
|
|
||||||
Handle(r.Delete)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
req.BatchSetGroup(ag, reqs[:])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,73 +17,34 @@ func InitMachineRouter(router *gin.RouterGroup) {
|
|||||||
|
|
||||||
machines := router.Group("machines")
|
machines := router.Group("machines")
|
||||||
{
|
{
|
||||||
machines.GET("", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).Handle(m.Machines)
|
|
||||||
})
|
|
||||||
|
|
||||||
machines.GET(":machineId/stats", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).Handle(m.MachineStats)
|
|
||||||
})
|
|
||||||
|
|
||||||
machines.GET(":machineId/process", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).Handle(m.GetProcess)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 终止进程
|
|
||||||
killProcessL := req.NewLogInfo("终止进程").WithSave(true)
|
|
||||||
killProcessP := req.NewPermission("machine:killprocess")
|
|
||||||
machines.DELETE(":machineId/process", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithLog(killProcessL).
|
|
||||||
WithRequiredPermission(killProcessP).
|
|
||||||
Handle(m.KillProcess)
|
|
||||||
})
|
|
||||||
|
|
||||||
saveMachine := req.NewLogInfo("保存机器信息").WithSave(true)
|
|
||||||
saveMachineP := req.NewPermission("machine:update")
|
saveMachineP := req.NewPermission("machine:update")
|
||||||
machines.POST("", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithLog(saveMachine).
|
|
||||||
WithRequiredPermission(saveMachineP).
|
|
||||||
Handle(m.SaveMachine)
|
|
||||||
})
|
|
||||||
|
|
||||||
machines.POST("test-conn", func(c *gin.Context) {
|
reqs := [...]*req.Conf{
|
||||||
req.NewCtxWithGin(c).
|
req.NewGet("", m.Machines),
|
||||||
Handle(m.TestConn)
|
|
||||||
})
|
|
||||||
|
|
||||||
changeStatus := req.NewLogInfo("调整机器状态").WithSave(true)
|
req.NewGet(":machineId/stats", m.MachineStats),
|
||||||
machines.PUT(":machineId/:status", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithLog(changeStatus).
|
|
||||||
WithRequiredPermission(saveMachineP).
|
|
||||||
Handle(m.ChangeStatus)
|
|
||||||
})
|
|
||||||
|
|
||||||
delMachine := req.NewLogInfo("删除机器").WithSave(true)
|
req.NewGet(":machineId/process", m.GetProcess),
|
||||||
machines.DELETE(":machineId", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithLog(delMachine).
|
|
||||||
Handle(m.DeleteMachine)
|
|
||||||
})
|
|
||||||
|
|
||||||
closeCli := req.NewLogInfo("关闭机器客户端").WithSave(true)
|
req.NewDelete(":machineId/process", m.KillProcess).Log(req.NewLogSave("终止进程")).RequiredPermissionCode("machine:killprocess"),
|
||||||
closeCliP := req.NewPermission("machine:close-cli")
|
|
||||||
machines.DELETE(":machineId/close-cli", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithLog(closeCli).
|
|
||||||
WithRequiredPermission(closeCliP).
|
|
||||||
Handle(m.CloseCli)
|
|
||||||
})
|
|
||||||
|
|
||||||
|
req.NewPost("", m.SaveMachine).Log(req.NewLogSave("保存机器信息")).RequiredPermission(saveMachineP),
|
||||||
|
|
||||||
|
req.NewPost("test-conn", m.TestConn),
|
||||||
|
|
||||||
|
req.NewPut(":machineId/:status", m.ChangeStatus).Log(req.NewLogSave("调整机器状态")).RequiredPermission(saveMachineP),
|
||||||
|
|
||||||
|
req.NewDelete(":machineId", m.DeleteMachine).Log(req.NewLogSave("删除机器")),
|
||||||
|
|
||||||
|
req.NewDelete(":machineId/close-cli", m.CloseCli).Log(req.NewLogSave("关闭机器客户端")).RequiredPermissionCode("machine:close-cli"),
|
||||||
|
|
||||||
|
// 获取机器终端回放记录的相应文件夹名或文件名,目前具有保存机器信息的权限标识才有权限查看终端回放
|
||||||
|
req.NewGet("rec/names", m.MachineRecDirNames).RequiredPermission(saveMachineP),
|
||||||
|
}
|
||||||
|
|
||||||
|
req.BatchSetGroup(machines, reqs[:])
|
||||||
|
|
||||||
|
// 终端连接
|
||||||
machines.GET(":machineId/terminal", m.WsSSH)
|
machines.GET(":machineId/terminal", m.WsSSH)
|
||||||
|
|
||||||
// 获取机器终端回放记录的相应文件夹名或文件名,目前具有保存机器信息的权限标识才有权限查看终端回放
|
|
||||||
machines.GET("rec/names", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithRequiredPermission(saveMachineP).
|
|
||||||
Handle(m.MachineRecDirNames)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,84 +11,36 @@ import (
|
|||||||
|
|
||||||
func InitMachineFileRouter(router *gin.RouterGroup) {
|
func InitMachineFileRouter(router *gin.RouterGroup) {
|
||||||
machineFile := router.Group("machines")
|
machineFile := router.Group("machines")
|
||||||
{
|
|
||||||
mf := &api.MachineFile{
|
|
||||||
MachineFileApp: application.GetMachineFileApp(),
|
|
||||||
MsgApp: msgapp.GetMsgApp(),
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取指定机器文件列表
|
mf := &api.MachineFile{
|
||||||
machineFile.GET(":machineId/files", func(c *gin.Context) {
|
MachineFileApp: application.GetMachineFileApp(),
|
||||||
req.NewCtxWithGin(c).Handle(mf.MachineFiles)
|
MsgApp: msgapp.GetMsgApp(),
|
||||||
})
|
|
||||||
|
|
||||||
// 新增修改机器文件
|
|
||||||
addFileConf := req.NewLogInfo("机器-新增文件配置").WithSave(true)
|
|
||||||
afcP := req.NewPermission("machine:file:add")
|
|
||||||
machineFile.POST(":machineId/files", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).WithLog(addFileConf).
|
|
||||||
WithRequiredPermission(afcP).
|
|
||||||
Handle(mf.SaveMachineFiles)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 删除机器文件
|
|
||||||
delFileConf := req.NewLogInfo("机器-删除文件配置").WithSave(true)
|
|
||||||
dfcP := req.NewPermission("machine:file:del")
|
|
||||||
machineFile.DELETE(":machineId/files/:fileId", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).WithLog(delFileConf).
|
|
||||||
WithRequiredPermission(dfcP).
|
|
||||||
Handle(mf.DeleteFile)
|
|
||||||
})
|
|
||||||
|
|
||||||
getContent := req.NewLogInfo("机器-获取文件内容").WithSave(true)
|
|
||||||
machineFile.GET(":machineId/files/:fileId/read", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).WithLog(getContent).
|
|
||||||
Handle(mf.ReadFileContent)
|
|
||||||
})
|
|
||||||
|
|
||||||
getDir := req.NewLogInfo("机器-获取目录")
|
|
||||||
machineFile.GET(":machineId/files/:fileId/read-dir", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).WithLog(getDir).
|
|
||||||
Handle(mf.GetDirEntry)
|
|
||||||
})
|
|
||||||
|
|
||||||
machineFile.GET(":machineId/files/:fileId/dir-size", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).Handle(mf.GetDirSize)
|
|
||||||
})
|
|
||||||
|
|
||||||
machineFile.GET(":machineId/files/:fileId/file-stat", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).Handle(mf.GetFileStat)
|
|
||||||
})
|
|
||||||
|
|
||||||
writeFile := req.NewLogInfo("机器-修改文件内容").WithSave(true)
|
|
||||||
wfP := req.NewPermission("machine:file:write")
|
|
||||||
machineFile.POST(":machineId/files/:fileId/write", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).WithLog(writeFile).
|
|
||||||
WithRequiredPermission(wfP).
|
|
||||||
Handle(mf.WriteFileContent)
|
|
||||||
})
|
|
||||||
|
|
||||||
createFile := req.NewLogInfo("机器-创建文件or目录").WithSave(true)
|
|
||||||
machineFile.POST(":machineId/files/:fileId/create-file", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).WithLog(createFile).
|
|
||||||
WithRequiredPermission(wfP).
|
|
||||||
Handle(mf.CreateFile)
|
|
||||||
})
|
|
||||||
|
|
||||||
uploadFile := req.NewLogInfo("机器-文件上传").WithSave(true)
|
|
||||||
ufP := req.NewPermission("machine:file:upload")
|
|
||||||
machineFile.POST(":machineId/files/:fileId/upload", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).WithLog(uploadFile).
|
|
||||||
WithRequiredPermission(ufP).
|
|
||||||
Handle(mf.UploadFile)
|
|
||||||
})
|
|
||||||
|
|
||||||
removeFile := req.NewLogInfo("机器-删除文件or文件夹").WithSave(true)
|
|
||||||
rfP := req.NewPermission("machine:file:rm")
|
|
||||||
machineFile.DELETE(":machineId/files/:fileId/remove", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).WithLog(removeFile).
|
|
||||||
WithRequiredPermission(rfP).
|
|
||||||
Handle(mf.RemoveFile)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reqs := [...]*req.Conf{
|
||||||
|
// 获取指定机器文件列表
|
||||||
|
req.NewGet(":machineId/files", mf.MachineFiles),
|
||||||
|
|
||||||
|
req.NewPost(":machineId/files", mf.SaveMachineFiles).Log(req.NewLogSave("机器-新增文件配置")).RequiredPermissionCode("machine:file:add"),
|
||||||
|
|
||||||
|
req.NewDelete(":machineId/files/:fileId", mf.DeleteFile).Log(req.NewLogSave("机器-删除文件配置")).RequiredPermissionCode("machine:file:del"),
|
||||||
|
|
||||||
|
req.NewGet(":machineId/files/:fileId/read", mf.ReadFileContent).Log(req.NewLogSave("机器-获取文件内容")),
|
||||||
|
|
||||||
|
req.NewGet(":machineId/files/:fileId/read-dir", mf.GetDirEntry).Log(req.NewLogSave("机器-获取目录")),
|
||||||
|
|
||||||
|
req.NewGet(":machineId/files/:fileId/dir-size", mf.GetDirSize),
|
||||||
|
|
||||||
|
req.NewGet(":machineId/files/:fileId/file-stat", mf.GetFileStat),
|
||||||
|
|
||||||
|
req.NewPost(":machineId/files/:fileId/write", mf.WriteFileContent).Log(req.NewLogSave("机器-修改文件内容")).RequiredPermissionCode("machine:file:write"),
|
||||||
|
|
||||||
|
req.NewPost(":machineId/files/:fileId/create-file", mf.CreateFile).Log(req.NewLogSave("机器-创建文件or目录")),
|
||||||
|
|
||||||
|
req.NewPost(":machineId/files/:fileId/upload", mf.UploadFile).Log(req.NewLogSave("机器-文件上传")).RequiredPermissionCode("machine:file:upload"),
|
||||||
|
|
||||||
|
req.NewDelete(":machineId/files/:fileId/remove", mf.RemoveFile).Log(req.NewLogSave("机器-删除文件or文件夹")).RequiredPermissionCode("machine:file:rm"),
|
||||||
|
}
|
||||||
|
|
||||||
|
req.BatchSetGroup(machineFile, reqs[:])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,43 +11,23 @@ import (
|
|||||||
|
|
||||||
func InitMachineScriptRouter(router *gin.RouterGroup) {
|
func InitMachineScriptRouter(router *gin.RouterGroup) {
|
||||||
machines := router.Group("machines")
|
machines := router.Group("machines")
|
||||||
{
|
ms := &api.MachineScript{
|
||||||
ms := &api.MachineScript{
|
MachineScriptApp: application.GetMachineScriptApp(),
|
||||||
MachineScriptApp: application.GetMachineScriptApp(),
|
MachineApp: application.GetMachineApp(),
|
||||||
MachineApp: application.GetMachineApp(),
|
TagApp: tagapp.GetTagTreeApp(),
|
||||||
TagApp: tagapp.GetTagTreeApp(),
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取指定机器脚本列表
|
|
||||||
machines.GET(":machineId/scripts", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).Handle(ms.MachineScripts)
|
|
||||||
})
|
|
||||||
|
|
||||||
saveMachienScriptLog := req.NewLogInfo("机器-保存脚本").WithSave(true)
|
|
||||||
smsP := req.NewPermission("machine:script:save")
|
|
||||||
// 保存脚本
|
|
||||||
machines.POST(":machineId/scripts", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).WithLog(saveMachienScriptLog).
|
|
||||||
WithRequiredPermission(smsP).
|
|
||||||
Handle(ms.SaveMachineScript)
|
|
||||||
})
|
|
||||||
|
|
||||||
deleteLog := req.NewLogInfo("机器-删除脚本").WithSave(true)
|
|
||||||
dP := req.NewPermission("machine:script:del")
|
|
||||||
// 保存脚本
|
|
||||||
machines.DELETE(":machineId/scripts/:scriptId", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).WithLog(deleteLog).
|
|
||||||
WithRequiredPermission(dP).
|
|
||||||
Handle(ms.DeleteMachineScript)
|
|
||||||
})
|
|
||||||
|
|
||||||
runLog := req.NewLogInfo("机器-执行脚本").WithSave(true)
|
|
||||||
rP := req.NewPermission("machine:script:run")
|
|
||||||
// 运行脚本
|
|
||||||
machines.GET(":machineId/scripts/:scriptId/run", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).WithLog(runLog).
|
|
||||||
WithRequiredPermission(rP).
|
|
||||||
Handle(ms.RunMachineScript)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reqs := [...]*req.Conf{
|
||||||
|
// 获取指定机器脚本列表
|
||||||
|
req.NewGet(":machineId/scripts", ms.MachineScripts),
|
||||||
|
|
||||||
|
req.NewPost(":machineId/scripts", ms.SaveMachineScript).Log(req.NewLogSave("机器-保存脚本")).RequiredPermissionCode("machine:script:save"),
|
||||||
|
|
||||||
|
req.NewDelete(":machineId/scripts/:scriptId", ms.DeleteMachineScript).Log(req.NewLogSave("机器-删除脚本")).RequiredPermissionCode("machine:script:del"),
|
||||||
|
|
||||||
|
req.NewGet(":machineId/scripts/:scriptId/run", ms.RunMachineScript).Log(req.NewLogSave("机器-执行脚本")).RequiredPermissionCode("machine:script:run"),
|
||||||
|
}
|
||||||
|
|
||||||
|
req.BatchSetGroup(machines, reqs[:])
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import (
|
|||||||
"mayfly-go/pkg/ginx"
|
"mayfly-go/pkg/ginx"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
"mayfly-go/pkg/req"
|
"mayfly-go/pkg/req"
|
||||||
"mayfly-go/pkg/utils"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -27,8 +26,7 @@ type Mongo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Mongo) Mongos(rc *req.Ctx) {
|
func (m *Mongo) Mongos(rc *req.Ctx) {
|
||||||
condition := new(entity.MongoQuery)
|
queryCond, page := ginx.BindQueryAndPage[*entity.MongoQuery](rc.GinCtx, new(entity.MongoQuery))
|
||||||
condition.TagPathLike = rc.GinCtx.Query("tagPath")
|
|
||||||
|
|
||||||
// 不存在可访问标签id,即没有可操作数据
|
// 不存在可访问标签id,即没有可操作数据
|
||||||
tagIds := m.TagApp.ListTagIdByAccountId(rc.LoginAccount.Id)
|
tagIds := m.TagApp.ListTagIdByAccountId(rc.LoginAccount.Id)
|
||||||
@@ -36,16 +34,14 @@ func (m *Mongo) Mongos(rc *req.Ctx) {
|
|||||||
rc.ResData = model.EmptyPageResult[any]()
|
rc.ResData = model.EmptyPageResult[any]()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
condition.TagIds = tagIds
|
queryCond.TagIds = tagIds
|
||||||
rc.ResData = m.MongoApp.GetPageList(condition, ginx.GetPageParam(rc.GinCtx), new([]entity.Mongo))
|
|
||||||
|
rc.ResData = m.MongoApp.GetPageList(queryCond, page, new([]entity.Mongo))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Mongo) Save(rc *req.Ctx) {
|
func (m *Mongo) Save(rc *req.Ctx) {
|
||||||
form := &form.Mongo{}
|
form := &form.Mongo{}
|
||||||
ginx.BindJsonAndValid(rc.GinCtx, form)
|
mongo := ginx.BindJsonAndCopyTo[*entity.Mongo](rc.GinCtx, form, new(entity.Mongo))
|
||||||
|
|
||||||
mongo := new(entity.Mongo)
|
|
||||||
utils.Copy(mongo, form)
|
|
||||||
|
|
||||||
// 密码脱敏记录日志
|
// 密码脱敏记录日志
|
||||||
form.Uri = func(str string) string {
|
form.Uri = func(str string) string {
|
||||||
|
|||||||
@@ -8,9 +8,7 @@ type MongoQuery struct {
|
|||||||
Name string
|
Name string
|
||||||
Uri string
|
Uri string
|
||||||
SshTunnelMachineId uint64 // ssh隧道机器id
|
SshTunnelMachineId uint64 // ssh隧道机器id
|
||||||
TagId uint64 `json:"tagId"`
|
TagPath string `json:"tagPath" form:"tagPath"`
|
||||||
TagPath string `json:"tagPath"`
|
|
||||||
|
|
||||||
TagIds []uint64
|
TagIds []uint64
|
||||||
TagPathLike string
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ func (d *mongoRepoImpl) GetList(condition *entity.MongoQuery, pageParam *model.P
|
|||||||
qd := gormx.NewQuery(new(entity.Mongo)).
|
qd := gormx.NewQuery(new(entity.Mongo)).
|
||||||
Like("name", condition.Name).
|
Like("name", condition.Name).
|
||||||
In("tag_id", condition.TagIds).
|
In("tag_id", condition.TagIds).
|
||||||
RLike("tag_path", condition.TagPathLike).
|
RLike("tag_path", condition.TagPath).
|
||||||
OrderByAsc("tag_path")
|
OrderByAsc("tag_path")
|
||||||
return gormx.PageQuery(qd, pageParam, toEntity)
|
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||||
}
|
}
|
||||||
@@ -29,9 +29,6 @@ func (d *mongoRepoImpl) Count(condition *entity.MongoQuery) int64 {
|
|||||||
if len(condition.TagIds) > 0 {
|
if len(condition.TagIds) > 0 {
|
||||||
where["tag_id"] = condition.TagIds
|
where["tag_id"] = condition.TagIds
|
||||||
}
|
}
|
||||||
if condition.TagId != 0 {
|
|
||||||
where["tag_id"] = condition.TagId
|
|
||||||
}
|
|
||||||
return gormx.CountByCond(new(entity.Mongo), where)
|
return gormx.CountByCond(new(entity.Mongo), where)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,78 +11,41 @@ import (
|
|||||||
|
|
||||||
func InitMongoRouter(router *gin.RouterGroup) {
|
func InitMongoRouter(router *gin.RouterGroup) {
|
||||||
m := router.Group("mongos")
|
m := router.Group("mongos")
|
||||||
{
|
|
||||||
ma := &api.Mongo{
|
|
||||||
MongoApp: application.GetMongoApp(),
|
|
||||||
TagApp: tagapp.GetTagTreeApp(),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
ma := &api.Mongo{
|
||||||
|
MongoApp: application.GetMongoApp(),
|
||||||
|
TagApp: tagapp.GetTagTreeApp(),
|
||||||
|
}
|
||||||
|
|
||||||
|
reqs := [...]*req.Conf{
|
||||||
// 获取所有mongo列表
|
// 获取所有mongo列表
|
||||||
m.GET("", func(c *gin.Context) {
|
req.NewGet("", ma.Mongos),
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
Handle(ma.Mongos)
|
|
||||||
})
|
|
||||||
|
|
||||||
saveMongo := req.NewLogInfo("mongo-保存信息")
|
req.NewPost("", ma.Save).Log(req.NewLogSave("mongo-保存信息")),
|
||||||
m.POST("", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithLog(saveMongo).
|
|
||||||
Handle(ma.Save)
|
|
||||||
})
|
|
||||||
|
|
||||||
deleteMongo := req.NewLogInfo("mongo-删除信息")
|
req.NewDelete(":id", ma.DeleteMongo).Log(req.NewLogSave("mongo-删除信息")),
|
||||||
m.DELETE(":id", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithLog(deleteMongo).
|
|
||||||
Handle(ma.DeleteMongo)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 获取mongo下的所有数据库
|
// 获取mongo下的所有数据库
|
||||||
m.GET(":id/databases", func(c *gin.Context) {
|
req.NewGet(":id/databases", ma.Databases),
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
Handle(ma.Databases)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 获取mongo指定库的所有集合
|
// 获取mongo指定库的所有集合
|
||||||
m.GET(":id/collections", func(c *gin.Context) {
|
req.NewGet(":id/collections", ma.Collections),
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
Handle(ma.Collections)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 获取mongo runCommand
|
// mongo runCommand
|
||||||
m.POST(":id/run-command", func(c *gin.Context) {
|
req.NewPost(":id/run-command", ma.RunCommand).Log(req.NewLogSave("mongo-runCommand")),
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
Handle(ma.RunCommand)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 执行mongo find命令
|
// 执行mongo find命令
|
||||||
m.POST(":id/command/find", func(c *gin.Context) {
|
req.NewPost(":id/command/find", ma.FindCommand),
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
Handle(ma.FindCommand)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 执行mongo update by id命令
|
req.NewPost(":id/command/update-by-id", ma.UpdateByIdCommand).Log(req.NewLogSave("mongo-更新文档")),
|
||||||
updateDocById := req.NewLogInfo("mongo-更新文档").WithSave(true)
|
|
||||||
m.POST(":id/command/update-by-id", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithLog(updateDocById).
|
|
||||||
Handle(ma.UpdateByIdCommand)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 执行mongo delete by id命令
|
// 执行mongo delete by id命令
|
||||||
deleteDoc := req.NewLogInfo("mongo-删除文档").WithSave(true)
|
req.NewPost(":id/command/delete-by-id", ma.DeleteByIdCommand).Log(req.NewLogSave("mongo-删除文档")),
|
||||||
m.POST(":id/command/delete-by-id", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithLog(deleteDoc).
|
|
||||||
Handle(ma.DeleteByIdCommand)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 执行mongo insert 命令
|
// 执行mongo insert 命令
|
||||||
insertDoc := req.NewLogInfo("mongo-新增文档").WithSave(true)
|
req.NewPost(":id/command/insert", ma.InsertOneCommand).Log(req.NewLogSave("mogno-插入文档")),
|
||||||
m.POST(":id/command/insert", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithLog(insertDoc).
|
|
||||||
Handle(ma.InsertOneCommand)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
req.BatchSetGroup(m, reqs[:])
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,9 +13,6 @@ func InitMsgRouter(router *gin.RouterGroup) {
|
|||||||
a := &api.Msg{
|
a := &api.Msg{
|
||||||
MsgApp: application.GetMsgApp(),
|
MsgApp: application.GetMsgApp(),
|
||||||
}
|
}
|
||||||
{
|
|
||||||
msg.GET("/self", func(c *gin.Context) {
|
req.NewGet("/self", a.GetMsgs).Group(msg)
|
||||||
req.NewCtxWithGin(c).Handle(a.GetMsgs)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,8 +25,7 @@ type Redis struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Redis) RedisList(rc *req.Ctx) {
|
func (r *Redis) RedisList(rc *req.Ctx) {
|
||||||
condition := new(entity.RedisQuery)
|
queryCond, page := ginx.BindQueryAndPage[*entity.RedisQuery](rc.GinCtx, new(entity.RedisQuery))
|
||||||
condition.TagPathLike = rc.GinCtx.Query("tagPath")
|
|
||||||
|
|
||||||
// 不存在可访问标签id,即没有可操作数据
|
// 不存在可访问标签id,即没有可操作数据
|
||||||
tagIds := r.TagApp.ListTagIdByAccountId(rc.LoginAccount.Id)
|
tagIds := r.TagApp.ListTagIdByAccountId(rc.LoginAccount.Id)
|
||||||
@@ -34,16 +33,14 @@ func (r *Redis) RedisList(rc *req.Ctx) {
|
|||||||
rc.ResData = model.EmptyPageResult[any]()
|
rc.ResData = model.EmptyPageResult[any]()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
condition.TagIds = tagIds
|
queryCond.TagIds = tagIds
|
||||||
rc.ResData = r.RedisApp.GetPageList(condition, ginx.GetPageParam(rc.GinCtx), new([]vo.Redis))
|
|
||||||
|
rc.ResData = r.RedisApp.GetPageList(queryCond, page, new([]vo.Redis))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Redis) Save(rc *req.Ctx) {
|
func (r *Redis) Save(rc *req.Ctx) {
|
||||||
form := &form.Redis{}
|
form := &form.Redis{}
|
||||||
ginx.BindJsonAndValid(rc.GinCtx, form)
|
redis := ginx.BindJsonAndCopyTo[*entity.Redis](rc.GinCtx, form, new(entity.Redis))
|
||||||
|
|
||||||
redis := new(entity.Redis)
|
|
||||||
utils.Copy(redis, form)
|
|
||||||
|
|
||||||
// 密码解密,并使用解密后的赋值
|
// 密码解密,并使用解密后的赋值
|
||||||
originPwd, err := utils.DefaultRsaDecrypt(redis.Password, true)
|
originPwd, err := utils.DefaultRsaDecrypt(redis.Password, true)
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ type RedisQuery struct {
|
|||||||
Db string `orm:"column(database)" json:"db"`
|
Db string `orm:"column(database)" json:"db"`
|
||||||
SshTunnelMachineId int `orm:"column(ssh_tunnel_machine_id)" json:"sshTunnelMachineId"` // ssh隧道机器id
|
SshTunnelMachineId int `orm:"column(ssh_tunnel_machine_id)" json:"sshTunnelMachineId"` // ssh隧道机器id
|
||||||
Remark string
|
Remark string
|
||||||
TagId uint64
|
|
||||||
|
|
||||||
TagIds []uint64
|
TagIds []uint64
|
||||||
TagPathLike string
|
TagPath string `form:"tagPath"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ func (r *redisRepoImpl) GetRedisList(condition *entity.RedisQuery, pageParam *mo
|
|||||||
qd := gormx.NewQuery(new(entity.Redis)).
|
qd := gormx.NewQuery(new(entity.Redis)).
|
||||||
Like("host", condition.Host).
|
Like("host", condition.Host).
|
||||||
In("tag_id", condition.TagIds).
|
In("tag_id", condition.TagIds).
|
||||||
RLike("tag_path", condition.TagPathLike).
|
RLike("tag_path", condition.TagPath).
|
||||||
OrderByAsc("tag_path")
|
OrderByAsc("tag_path")
|
||||||
return gormx.PageQuery(qd, pageParam, toEntity)
|
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||||
}
|
}
|
||||||
@@ -29,9 +29,6 @@ func (r *redisRepoImpl) Count(condition *entity.RedisQuery) int64 {
|
|||||||
if len(condition.TagIds) > 0 {
|
if len(condition.TagIds) > 0 {
|
||||||
where["tag_id"] = condition.TagIds
|
where["tag_id"] = condition.TagIds
|
||||||
}
|
}
|
||||||
if condition.TagId != 0 {
|
|
||||||
where["tag_id"] = condition.TagId
|
|
||||||
}
|
|
||||||
|
|
||||||
return gormx.CountByCond(new(entity.Redis), where)
|
return gormx.CountByCond(new(entity.Redis), where)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,215 +11,98 @@ import (
|
|||||||
|
|
||||||
func InitRedisRouter(router *gin.RouterGroup) {
|
func InitRedisRouter(router *gin.RouterGroup) {
|
||||||
redis := router.Group("redis")
|
redis := router.Group("redis")
|
||||||
{
|
|
||||||
rs := &api.Redis{
|
|
||||||
RedisApp: application.GetRedisApp(),
|
|
||||||
TagApp: tagapp.GetTagTreeApp(),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
rs := &api.Redis{
|
||||||
|
RedisApp: application.GetRedisApp(),
|
||||||
|
TagApp: tagapp.GetTagTreeApp(),
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存数据权限
|
||||||
|
saveDataP := req.NewPermission("redis:data:save")
|
||||||
|
// 删除数据权限
|
||||||
|
deleteDataP := req.NewPermission("redis:data:del")
|
||||||
|
|
||||||
|
reqs := [...]*req.Conf{
|
||||||
// 获取redis list
|
// 获取redis list
|
||||||
redis.GET("", func(c *gin.Context) {
|
req.NewGet("", rs.RedisList),
|
||||||
req.NewCtxWithGin(c).Handle(rs.RedisList)
|
|
||||||
})
|
|
||||||
|
|
||||||
save := req.NewLogInfo("redis-保存信息").WithSave(true)
|
req.NewPost("", rs.Save).Log(req.NewLogSave("redis-保存信息")),
|
||||||
redis.POST("", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).WithLog(save).Handle(rs.Save)
|
|
||||||
})
|
|
||||||
|
|
||||||
redis.GET(":id/pwd", func(c *gin.Context) {
|
req.NewGet(":id/pwd", rs.GetRedisPwd),
|
||||||
req.NewCtxWithGin(c).Handle(rs.GetRedisPwd)
|
|
||||||
})
|
|
||||||
|
|
||||||
delRedis := req.NewLogInfo("redis-删除信息").WithSave(true)
|
req.NewDelete(":id", rs.DeleteRedis).Log(req.NewLogSave("redis-删除信息")),
|
||||||
redis.DELETE(":id", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).WithLog(delRedis).Handle(rs.DeleteRedis)
|
|
||||||
})
|
|
||||||
|
|
||||||
redis.GET(":id/info", func(c *gin.Context) {
|
req.NewGet("/:id/info", rs.RedisInfo),
|
||||||
req.NewCtxWithGin(c).Handle(rs.RedisInfo)
|
|
||||||
})
|
|
||||||
|
|
||||||
redis.GET(":id/cluster-info", func(c *gin.Context) {
|
req.NewGet(":id/cluster-info", rs.ClusterInfo),
|
||||||
req.NewCtxWithGin(c).Handle(rs.ClusterInfo)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 获取指定redis keys
|
// 获取指定redis keys
|
||||||
redis.POST(":id/:db/scan", func(c *gin.Context) {
|
req.NewPost(":id/:db/scan", rs.Scan),
|
||||||
req.NewCtxWithGin(c).Handle(rs.Scan)
|
|
||||||
})
|
|
||||||
|
|
||||||
redis.GET(":id/:db/key-ttl", func(c *gin.Context) {
|
req.NewGet(":id/:db/key-ttl", rs.TtlKey),
|
||||||
req.NewCtxWithGin(c).Handle(rs.TtlKey)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 保存数据权限
|
req.NewDelete(":id/:db/key", rs.DeleteKey).Log(req.NewLogSave("redis-删除key")).RequiredPermission(deleteDataP),
|
||||||
saveDataP := req.NewPermission("redis:data:save")
|
|
||||||
// 删除数据权限
|
|
||||||
deleteDataP := req.NewPermission("redis:data:del")
|
|
||||||
|
|
||||||
// 删除key
|
req.NewPost(":id/:db/rename-key", rs.RenameKey).Log(req.NewLogSave("redis-重命名key")).RequiredPermission(saveDataP),
|
||||||
deleteKeyL := req.NewLogInfo("redis-删除key").WithSave(true)
|
|
||||||
redis.DELETE(":id/:db/key", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithLog(deleteKeyL).
|
|
||||||
WithRequiredPermission(deleteDataP).
|
|
||||||
Handle(rs.DeleteKey)
|
|
||||||
})
|
|
||||||
|
|
||||||
renameKeyL := req.NewLogInfo("redis-重命名key").WithSave(true)
|
req.NewPost(":id/:db/expire-key", rs.ExpireKey).Log(req.NewLogSave("redis-设置key过期时间")).RequiredPermission(saveDataP),
|
||||||
redis.POST(":id/:db/rename-key", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithLog(renameKeyL).
|
|
||||||
WithRequiredPermission(saveDataP).
|
|
||||||
Handle(rs.RenameKey)
|
|
||||||
})
|
|
||||||
|
|
||||||
expireKeyL := req.NewLogInfo("redis-设置key过期时间").WithSave(true)
|
req.NewDelete(":id/:db/persist-key", rs.PersistKey).Log(req.NewLogSave("redis-移除key过期时间")).RequiredPermission(saveDataP),
|
||||||
redis.POST(":id/:db/expire-key", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithLog(expireKeyL).
|
|
||||||
WithRequiredPermission(saveDataP).
|
|
||||||
Handle(rs.ExpireKey)
|
|
||||||
})
|
|
||||||
|
|
||||||
persistKeyL := req.NewLogInfo("redis-移除key过期时间").WithSave(true)
|
req.NewDelete(":id/:db/flushdb", rs.FlushDb).Log(req.NewLogSave("redis-flushdb")).RequiredPermission(deleteDataP),
|
||||||
redis.DELETE(":id/:db/persist-key", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithLog(persistKeyL).
|
|
||||||
WithRequiredPermission(saveDataP).
|
|
||||||
Handle(rs.PersistKey)
|
|
||||||
})
|
|
||||||
|
|
||||||
flushDbL := req.NewLogInfo("redis-flushdb").WithSave(true)
|
|
||||||
redis.DELETE(":id/:db/flushdb", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithLog(flushDbL).
|
|
||||||
WithRequiredPermission(saveDataP).
|
|
||||||
Handle(rs.FlushDb)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 获取string类型值
|
// 获取string类型值
|
||||||
redis.GET(":id/:db/string-value", func(c *gin.Context) {
|
req.NewGet(":id/:db/string-value", rs.GetStringValue),
|
||||||
req.NewCtxWithGin(c).Handle(rs.GetStringValue)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 设置string类型值
|
// 设置string类型值
|
||||||
setStringL := req.NewLogInfo("redis-setString").WithSave(true)
|
req.NewPost(":id/:db/string-value", rs.SetStringValue).Log(req.NewLogSave("redis-setString")).RequiredPermission(saveDataP),
|
||||||
redis.POST(":id/:db/string-value", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithLog(setStringL).
|
|
||||||
WithRequiredPermission(saveDataP).
|
|
||||||
Handle(rs.SetStringValue)
|
|
||||||
})
|
|
||||||
|
|
||||||
// hscan
|
// ———————————————— hash操作 ————————————————
|
||||||
redis.GET(":id/:db/hscan", func(c *gin.Context) {
|
req.NewGet(":id/:db/hscan", rs.Hscan),
|
||||||
req.NewCtxWithGin(c).Handle(rs.Hscan)
|
|
||||||
})
|
|
||||||
|
|
||||||
redis.GET(":id/:db/hget", func(c *gin.Context) {
|
req.NewGet(":id/:db/hget", rs.Hget),
|
||||||
req.NewCtxWithGin(c).Handle(rs.Hget)
|
|
||||||
})
|
|
||||||
|
|
||||||
hsetL := req.NewLogInfo("redis-hset").WithSave(true)
|
req.NewPost(":id/:db/hset", rs.Hset).Log(req.NewLogSave("redis-hset")).RequiredPermission(saveDataP),
|
||||||
redis.POST(":id/:db/hset", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithLog(hsetL).
|
|
||||||
WithRequiredPermission(saveDataP).
|
|
||||||
Handle(rs.Hset)
|
|
||||||
})
|
|
||||||
|
|
||||||
hdelL := req.NewLogInfo("redis-hdel").WithSave(true)
|
req.NewDelete(":id/:db/hdel", rs.Hdel).Log(req.NewLogSave("redis-hdel")).RequiredPermission(deleteDataP),
|
||||||
redis.DELETE(":id/:db/hdel", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithLog(hdelL).
|
|
||||||
WithRequiredPermission(deleteDataP).
|
|
||||||
Handle(rs.Hdel)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 设置hash类型值
|
// 设置hash类型值
|
||||||
setHashValueL := req.NewLogInfo("redis-setHashValue").WithSave(true)
|
req.NewPost(":id/:db/hash-value", rs.SetHashValue).Log(req.NewLogSave("redis-setHashValue")).RequiredPermission(saveDataP),
|
||||||
redis.POST(":id/:db/hash-value", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithLog(setHashValueL).
|
|
||||||
WithRequiredPermission(saveDataP).
|
|
||||||
Handle(rs.SetHashValue)
|
|
||||||
})
|
|
||||||
|
|
||||||
// set操作
|
// --------------- set操作 ----------------
|
||||||
redis.GET(":id/:db/set-value", func(c *gin.Context) {
|
req.NewGet(":id/:db/set-value", rs.GetSetValue),
|
||||||
req.NewCtxWithGin(c).Handle(rs.GetSetValue)
|
|
||||||
})
|
|
||||||
|
|
||||||
redis.POST(":id/:db/set-value", func(c *gin.Context) {
|
req.NewPost(":id/:db/set-value", rs.SetSetValue).RequiredPermission(saveDataP),
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithRequiredPermission(saveDataP).
|
|
||||||
Handle(rs.SetSetValue)
|
|
||||||
})
|
|
||||||
|
|
||||||
redis.GET(":id/:db/scard", func(c *gin.Context) {
|
req.NewGet(":id/:db/scard", rs.Scard),
|
||||||
req.NewCtxWithGin(c).Handle(rs.Scard)
|
|
||||||
})
|
|
||||||
|
|
||||||
redis.POST(":id/:db/sscan", func(c *gin.Context) {
|
req.NewPost(":id/:db/sscan", rs.Sscan),
|
||||||
req.NewCtxWithGin(c).Handle(rs.Sscan)
|
|
||||||
})
|
|
||||||
|
|
||||||
redis.POST(":id/:db/sadd", func(c *gin.Context) {
|
req.NewPost(":id/:db/sadd", rs.Sadd).RequiredPermission(saveDataP),
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithRequiredPermission(saveDataP).
|
|
||||||
Handle(rs.Sadd)
|
|
||||||
})
|
|
||||||
|
|
||||||
redis.POST(":id/:db/srem", func(c *gin.Context) {
|
req.NewPost(":id/:db/srem", rs.Srem).RequiredPermission(deleteDataP),
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithRequiredPermission(deleteDataP).
|
|
||||||
Handle(rs.Srem)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 获取list类型值
|
// --------------- list操作 ----------------
|
||||||
redis.GET(":id/:db/list-value", func(c *gin.Context) {
|
req.NewGet(":id/:db/list-value", rs.GetListValue),
|
||||||
req.NewCtxWithGin(c).Handle(rs.GetListValue)
|
|
||||||
})
|
|
||||||
|
|
||||||
redis.POST(":id/:db/list-value", func(c *gin.Context) {
|
req.NewPost(":id/:db/list-value", rs.SaveListValue).RequiredPermission(saveDataP),
|
||||||
req.NewCtxWithGin(c).Handle(rs.SaveListValue)
|
|
||||||
})
|
|
||||||
|
|
||||||
redis.POST(":id/:db/list-value/lset", func(c *gin.Context) {
|
req.NewPost(":id/:db/list-value/lset", rs.SetListValue).RequiredPermission(saveDataP),
|
||||||
req.NewCtxWithGin(c).Handle(rs.SetListValue)
|
|
||||||
})
|
|
||||||
|
|
||||||
redis.POST(":id/:db/lrem", func(c *gin.Context) {
|
req.NewPost(":id/:db/lrem", rs.Lrem).RequiredPermission(deleteDataP),
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithRequiredPermission(deleteDataP).
|
|
||||||
Handle(rs.Lrem)
|
|
||||||
})
|
|
||||||
|
|
||||||
// zset操作
|
// --------------- zset操作 ----------------
|
||||||
redis.GET(":id/:db/zcard", func(c *gin.Context) {
|
req.NewGet(":id/:db/zcard", rs.ZCard),
|
||||||
req.NewCtxWithGin(c).Handle(rs.ZCard)
|
|
||||||
})
|
|
||||||
|
|
||||||
redis.GET(":id/:db/zscan", func(c *gin.Context) {
|
req.NewGet(":id/:db/zscan", rs.ZScan),
|
||||||
req.NewCtxWithGin(c).Handle(rs.ZScan)
|
|
||||||
})
|
|
||||||
|
|
||||||
redis.GET(":id/:db/zrevrange", func(c *gin.Context) {
|
req.NewGet(":id/:db/zrevrange", rs.ZRevRange),
|
||||||
req.NewCtxWithGin(c).Handle(rs.ZRevRange)
|
|
||||||
})
|
|
||||||
|
|
||||||
redis.POST(":id/:db/zrem", func(c *gin.Context) {
|
req.NewPost(":id/:db/zrem", rs.ZRem).Log(req.NewLogSave("redis-zrem")).RequiredPermission(deleteDataP),
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithRequiredPermission(deleteDataP).
|
|
||||||
Handle(rs.ZRem)
|
|
||||||
})
|
|
||||||
|
|
||||||
redis.POST(":id/:db/zadd", func(c *gin.Context) {
|
req.NewPost(":id/:db/zadd", rs.ZAdd).RequiredPermission(saveDataP),
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithRequiredPermission(saveDataP).
|
|
||||||
Handle(rs.ZAdd)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
req.BatchSetGroup(redis, reqs[:])
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -283,11 +283,7 @@ func (a *Account) AccountInfo(rc *req.Ctx) {
|
|||||||
|
|
||||||
// 更新个人账号信息
|
// 更新个人账号信息
|
||||||
func (a *Account) UpdateAccount(rc *req.Ctx) {
|
func (a *Account) UpdateAccount(rc *req.Ctx) {
|
||||||
updateForm := &form.AccountUpdateForm{}
|
updateAccount := ginx.BindJsonAndCopyTo[*entity.Account](rc.GinCtx, new(form.AccountUpdateForm), new(entity.Account))
|
||||||
ginx.BindJsonAndValid(rc.GinCtx, updateForm)
|
|
||||||
|
|
||||||
updateAccount := new(entity.Account)
|
|
||||||
utils.Copy(updateAccount, updateForm)
|
|
||||||
// 账号id为登录者账号
|
// 账号id为登录者账号
|
||||||
updateAccount.Id = rc.LoginAccount.Id
|
updateAccount.Id = rc.LoginAccount.Id
|
||||||
|
|
||||||
@@ -310,11 +306,10 @@ func (a *Account) Accounts(rc *req.Ctx) {
|
|||||||
// @router /accounts
|
// @router /accounts
|
||||||
func (a *Account) SaveAccount(rc *req.Ctx) {
|
func (a *Account) SaveAccount(rc *req.Ctx) {
|
||||||
form := &form.AccountCreateForm{}
|
form := &form.AccountCreateForm{}
|
||||||
ginx.BindJsonAndValid(rc.GinCtx, form)
|
account := ginx.BindJsonAndCopyTo(rc.GinCtx, form, new(entity.Account))
|
||||||
rc.ReqParam = form
|
|
||||||
|
|
||||||
account := &entity.Account{}
|
form.Password = "*****"
|
||||||
utils.Copy(account, form)
|
rc.ReqParam = form
|
||||||
account.SetBaseInfo(rc.LoginAccount)
|
account.SetBaseInfo(rc.LoginAccount)
|
||||||
|
|
||||||
if account.Id == 0 {
|
if account.Id == 0 {
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
"mayfly-go/pkg/ginx"
|
"mayfly-go/pkg/ginx"
|
||||||
"mayfly-go/pkg/req"
|
"mayfly-go/pkg/req"
|
||||||
"mayfly-go/pkg/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
@@ -27,13 +26,9 @@ func (c *Config) GetConfigValueByKey(rc *req.Ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) SaveConfig(rc *req.Ctx) {
|
func (c *Config) SaveConfig(rc *req.Ctx) {
|
||||||
g := rc.GinCtx
|
|
||||||
form := &form.ConfigForm{}
|
form := &form.ConfigForm{}
|
||||||
ginx.BindJsonAndValid(g, form)
|
config := ginx.BindJsonAndCopyTo(rc.GinCtx, form, new(entity.Config))
|
||||||
rc.ReqParam = form
|
rc.ReqParam = form
|
||||||
|
|
||||||
config := new(entity.Config)
|
|
||||||
utils.Copy(config, form)
|
|
||||||
config.SetBaseInfo(rc.LoginAccount)
|
config.SetBaseInfo(rc.LoginAccount)
|
||||||
c.ConfigApp.Save(config)
|
c.ConfigApp.Save(config)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
"mayfly-go/internal/sys/domain/entity"
|
"mayfly-go/internal/sys/domain/entity"
|
||||||
"mayfly-go/pkg/ginx"
|
"mayfly-go/pkg/ginx"
|
||||||
"mayfly-go/pkg/req"
|
"mayfly-go/pkg/req"
|
||||||
"mayfly-go/pkg/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Resource struct {
|
type Resource struct {
|
||||||
@@ -29,11 +28,10 @@ func (r *Resource) GetById(rc *req.Ctx) {
|
|||||||
func (r *Resource) SaveResource(rc *req.Ctx) {
|
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)
|
entity := ginx.BindJsonAndCopyTo(g, form, new(entity.Resource))
|
||||||
|
|
||||||
rc.ReqParam = form
|
rc.ReqParam = form
|
||||||
|
|
||||||
entity := new(entity.Resource)
|
|
||||||
utils.Copy(entity, form)
|
|
||||||
// 将meta转为json字符串存储
|
// 将meta转为json字符串存储
|
||||||
bytes, _ := json.Marshal(form.Meta)
|
bytes, _ := json.Marshal(form.Meta)
|
||||||
entity.Meta = string(bytes)
|
entity.Meta = string(bytes)
|
||||||
|
|||||||
@@ -27,13 +27,9 @@ func (r *Role) Roles(rc *req.Ctx) {
|
|||||||
|
|
||||||
// 保存角色信息
|
// 保存角色信息
|
||||||
func (r *Role) SaveRole(rc *req.Ctx) {
|
func (r *Role) SaveRole(rc *req.Ctx) {
|
||||||
g := rc.GinCtx
|
|
||||||
form := &form.RoleForm{}
|
form := &form.RoleForm{}
|
||||||
ginx.BindJsonAndValid(g, form)
|
role := ginx.BindJsonAndCopyTo(rc.GinCtx, form, new(entity.Role))
|
||||||
rc.ReqParam = form
|
rc.ReqParam = form
|
||||||
|
|
||||||
role := new(entity.Role)
|
|
||||||
utils.Copy(role, form)
|
|
||||||
role.SetBaseInfo(rc.LoginAccount)
|
role.SetBaseInfo(rc.LoginAccount)
|
||||||
|
|
||||||
r.RoleApp.SaveRole(role)
|
r.RoleApp.SaveRole(role)
|
||||||
|
|||||||
@@ -12,11 +12,6 @@ type Syslog struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Syslog) Syslogs(rc *req.Ctx) {
|
func (r *Syslog) Syslogs(rc *req.Ctx) {
|
||||||
g := rc.GinCtx
|
queryCond, page := ginx.BindQueryAndPage[*entity.SysLogQuery](rc.GinCtx, new(entity.SysLogQuery))
|
||||||
condition := &entity.Syslog{
|
rc.ResData = r.SyslogApp.GetPageList(queryCond, page, new([]entity.SysLog), "create_time DESC")
|
||||||
Type: int8(ginx.QueryInt(g, "type", 0)),
|
|
||||||
CreatorId: uint64(ginx.QueryInt(g, "creatorId", 0)),
|
|
||||||
Description: ginx.Query(g, "description", ""),
|
|
||||||
}
|
|
||||||
rc.ResData = r.SyslogApp.GetPageList(condition, ginx.GetPageParam(g), new([]entity.Syslog), "create_time DESC")
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Syslog interface {
|
type Syslog interface {
|
||||||
GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
GetPageList(condition *entity.SysLogQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||||
|
|
||||||
// 从请求上下文的参数保存系统日志
|
// 从请求上下文的参数保存系统日志
|
||||||
SaveFromReq(req *req.Ctx)
|
SaveFromReq(req *req.Ctx)
|
||||||
@@ -29,7 +29,7 @@ type syslogAppImpl struct {
|
|||||||
syslogRepo repository.Syslog
|
syslogRepo repository.Syslog
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *syslogAppImpl) GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
func (m *syslogAppImpl) GetPageList(condition *entity.SysLogQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||||
return m.syslogRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
return m.syslogRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,13 +38,13 @@ func (m *syslogAppImpl) SaveFromReq(req *req.Ctx) {
|
|||||||
if lg == nil {
|
if lg == nil {
|
||||||
lg = &model.LoginAccount{Id: 0, Username: "-"}
|
lg = &model.LoginAccount{Id: 0, Username: "-"}
|
||||||
}
|
}
|
||||||
syslog := new(entity.Syslog)
|
syslog := new(entity.SysLog)
|
||||||
syslog.CreateTime = time.Now()
|
syslog.CreateTime = time.Now()
|
||||||
syslog.Creator = lg.Username
|
syslog.Creator = lg.Username
|
||||||
syslog.CreatorId = lg.Id
|
syslog.CreatorId = lg.Id
|
||||||
syslog.Description = req.LogInfo.Description
|
syslog.Description = req.GetLogInfo().Description
|
||||||
|
|
||||||
if req.LogInfo.LogResp {
|
if req.GetLogInfo().LogResp {
|
||||||
respB, _ := json.Marshal(req.ResData)
|
respB, _ := json.Marshal(req.ResData)
|
||||||
syslog.Resp = string(respB)
|
syslog.Resp = string(respB)
|
||||||
}
|
}
|
||||||
|
|||||||
7
server/internal/sys/domain/entity/query.go
Normal file
7
server/internal/sys/domain/entity/query.go
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package entity
|
||||||
|
|
||||||
|
type SysLogQuery struct {
|
||||||
|
CreatorId uint64 `json:"creatorId" form:"creatorId"`
|
||||||
|
Type int8 `json:"type" form:"type"`
|
||||||
|
Description string `json:"description" form:"description"`
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@ package entity
|
|||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
// 系统操作日志
|
// 系统操作日志
|
||||||
type Syslog struct {
|
type SysLog struct {
|
||||||
Id uint64 `json:"id"`
|
Id uint64 `json:"id"`
|
||||||
CreateTime time.Time `json:"createTime"`
|
CreateTime time.Time `json:"createTime"`
|
||||||
CreatorId uint64 `json:"creatorId"`
|
CreatorId uint64 `json:"creatorId"`
|
||||||
@@ -15,7 +15,7 @@ type Syslog struct {
|
|||||||
Resp string `json:"resp"` // 响应结构
|
Resp string `json:"resp"` // 响应结构
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Syslog) TableName() string {
|
func (a *SysLog) TableName() string {
|
||||||
return "t_sys_log"
|
return "t_sys_log"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Syslog interface {
|
type Syslog interface {
|
||||||
GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
GetPageList(condition *entity.SysLogQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||||
|
|
||||||
Insert(log *entity.Syslog)
|
Insert(log *entity.SysLog)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,12 +13,12 @@ func newSyslogRepo() repository.Syslog {
|
|||||||
return new(syslogRepoImpl)
|
return new(syslogRepoImpl)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *syslogRepoImpl) GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
func (m *syslogRepoImpl) GetPageList(condition *entity.SysLogQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||||
qd := gormx.NewQuery(condition).Like("description", condition.Description).
|
qd := gormx.NewQuery(new(entity.SysLog)).Like("description", condition.Description).
|
||||||
Eq("creator_id", condition.CreatorId).Eq("type", condition.Type).WithOrderBy(orderBy...)
|
Eq("creator_id", condition.CreatorId).Eq("type", condition.Type).WithOrderBy(orderBy...)
|
||||||
return gormx.PageQuery(qd, pageParam, toEntity)
|
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *syslogRepoImpl) Insert(syslog *entity.Syslog) {
|
func (m *syslogRepoImpl) Insert(syslog *entity.SysLog) {
|
||||||
gormx.Insert(syslog)
|
gormx.Insert(syslog)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,107 +18,52 @@ func InitAccountRouter(router *gin.RouterGroup) {
|
|||||||
MsgApp: msgapp.GetMsgApp(),
|
MsgApp: msgapp.GetMsgApp(),
|
||||||
ConfigApp: application.GetConfigApp(),
|
ConfigApp: application.GetConfigApp(),
|
||||||
}
|
}
|
||||||
{
|
|
||||||
// 用户登录
|
|
||||||
loginLog := req.NewLogInfo("用户登录").WithSave(true)
|
|
||||||
account.POST("login", func(g *gin.Context) {
|
|
||||||
req.NewCtxWithGin(g).
|
|
||||||
DontNeedToken().
|
|
||||||
WithLog(loginLog).
|
|
||||||
Handle(a.Login)
|
|
||||||
})
|
|
||||||
|
|
||||||
account.POST("otp-verify", func(g *gin.Context) {
|
addAccountPermission := req.NewPermission("account:add")
|
||||||
req.NewCtxWithGin(g).
|
|
||||||
DontNeedToken().
|
reqs := [...]*req.Conf{
|
||||||
Handle(a.OtpVerify)
|
// 用户登录
|
||||||
})
|
req.NewPost("/login", a.Login).Log(req.NewLogSave("用户登录")).DontNeedToken(),
|
||||||
|
|
||||||
|
// otp双因素校验
|
||||||
|
req.NewPost("/otp-verify", a.OtpVerify).DontNeedToken(),
|
||||||
|
|
||||||
// 获取个人账号的权限资源信息
|
// 获取个人账号的权限资源信息
|
||||||
account.GET("/permissions", func(c *gin.Context) {
|
req.NewGet("/permissions", a.GetPermissions),
|
||||||
req.NewCtxWithGin(c).Handle(a.GetPermissions)
|
|
||||||
})
|
|
||||||
|
|
||||||
changePwdLog := req.NewLogInfo("用户修改密码").WithSave(true)
|
req.NewPost("/change-pwd", a.ChangePassword).DontNeedToken().Log(req.NewLogSave("用户修改密码")),
|
||||||
account.POST("change-pwd", func(g *gin.Context) {
|
|
||||||
req.NewCtxWithGin(g).
|
|
||||||
DontNeedToken().
|
|
||||||
WithLog(changePwdLog).
|
|
||||||
Handle(a.ChangePassword)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 获取个人账号信息
|
// 获取个人账号信息
|
||||||
account.GET("/self", func(c *gin.Context) {
|
req.NewGet("/self", a.AccountInfo),
|
||||||
req.NewCtxWithGin(c).Handle(a.AccountInfo)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 更新个人账号信息
|
// 更新个人账号信息
|
||||||
account.PUT("/self", func(c *gin.Context) {
|
req.NewPut("/self", a.UpdateAccount),
|
||||||
req.NewCtxWithGin(c).Handle(a.UpdateAccount)
|
|
||||||
})
|
|
||||||
|
|
||||||
/** 后台管理接口 **/
|
/** 后台管理接口 **/
|
||||||
|
|
||||||
// 获取所有用户列表
|
// 获取所有用户列表
|
||||||
account.GET("", func(c *gin.Context) {
|
req.NewGet("", a.Accounts),
|
||||||
req.NewCtxWithGin(c).Handle(a.Accounts)
|
|
||||||
})
|
|
||||||
|
|
||||||
createAccount := req.NewLogInfo("保存账号信息").WithSave(true)
|
req.NewPost("", a.SaveAccount).Log(req.NewLogSave("保存账号信息")).RequiredPermission(addAccountPermission),
|
||||||
addAccountPermission := req.NewPermission("account:add")
|
|
||||||
account.POST("", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithRequiredPermission(addAccountPermission).
|
|
||||||
WithLog(createAccount).
|
|
||||||
Handle(a.SaveAccount)
|
|
||||||
})
|
|
||||||
|
|
||||||
changeStatus := req.NewLogInfo("修改账号状态").WithSave(true)
|
req.NewPut("change-status/:id/:status", a.ChangeStatus).Log(req.NewLogSave("修改账号状态")).RequiredPermission(addAccountPermission),
|
||||||
account.PUT("change-status/:id/:status", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithLog(changeStatus).
|
|
||||||
Handle(a.ChangeStatus)
|
|
||||||
})
|
|
||||||
|
|
||||||
resetOtpSecret := req.NewLogInfo("重置OTP密钥").WithSave(true)
|
req.NewPut(":id/reset-otp", a.ResetOtpSecret).Log(req.NewLogSave("重置OTP密钥")).RequiredPermission(addAccountPermission),
|
||||||
account.PUT(":id/reset-otp", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithRequiredPermission(addAccountPermission).
|
|
||||||
WithLog(resetOtpSecret).
|
|
||||||
Handle(a.ResetOtpSecret)
|
|
||||||
})
|
|
||||||
|
|
||||||
delAccount := req.NewLogInfo("删除账号").WithSave(true)
|
req.NewDelete(":id", a.DeleteAccount).Log(req.NewLogSave("删除账号")).RequiredPermissionCode("account:del"),
|
||||||
delAccountPermission := req.NewPermission("account:del")
|
|
||||||
account.DELETE(":id", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithRequiredPermission(delAccountPermission).
|
|
||||||
WithLog(delAccount).
|
|
||||||
Handle(a.DeleteAccount)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 获取所有用户角色id列表
|
// 获取所有用户角色id列表
|
||||||
account.GET(":id/roleIds", func(c *gin.Context) {
|
req.NewGet(":id/roleIds", a.AccountRoleIds),
|
||||||
req.NewCtxWithGin(c).Handle(a.AccountRoleIds)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 保存用户角色
|
// 保存用户角色
|
||||||
saveAccountRole := req.NewLogInfo("保存用户角色").WithSave(true)
|
req.NewPost("/roles", a.SaveRoles).Log(req.NewLogSave("保存用户角色")).RequiredPermissionCode("account:saveRoles"),
|
||||||
sarPermission := req.NewPermission("account:saveRoles")
|
|
||||||
account.POST("/roles", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).WithLog(saveAccountRole).
|
|
||||||
WithRequiredPermission(sarPermission).
|
|
||||||
Handle(a.SaveRoles)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 获取用户角色
|
// 获取用户角色
|
||||||
account.GET(":id/roles", func(c *gin.Context) {
|
req.NewGet(":id/roles", a.AccountRoles),
|
||||||
req.NewCtxWithGin(c).Handle(a.AccountRoles)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 获取用户资源列表
|
// 获取用户资源列表
|
||||||
account.GET(":id/resources", func(c *gin.Context) {
|
req.NewGet(":id/resources", a.AccountResources),
|
||||||
req.NewCtxWithGin(c).Handle(a.AccountResources)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
req.BatchSetGroup(account, reqs[:])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ import (
|
|||||||
func InitCaptchaRouter(router *gin.RouterGroup) {
|
func InitCaptchaRouter(router *gin.RouterGroup) {
|
||||||
captcha := router.Group("sys/captcha")
|
captcha := router.Group("sys/captcha")
|
||||||
{
|
{
|
||||||
captcha.GET("", func(c *gin.Context) {
|
req.NewGet("", api.GenerateCaptcha).DontNeedToken().Group(captcha)
|
||||||
req.NewCtxWithGin(c).DontNeedToken().Handle(api.GenerateCaptcha)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,24 +10,18 @@ import (
|
|||||||
|
|
||||||
func InitSysConfigRouter(router *gin.RouterGroup) {
|
func InitSysConfigRouter(router *gin.RouterGroup) {
|
||||||
r := &api.Config{ConfigApp: application.GetConfigApp()}
|
r := &api.Config{ConfigApp: application.GetConfigApp()}
|
||||||
db := router.Group("sys/configs")
|
configG := router.Group("sys/configs")
|
||||||
{
|
|
||||||
baseP := req.NewPermission("config:base")
|
|
||||||
db.GET("", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).WithRequiredPermission(baseP).Handle(r.Configs)
|
|
||||||
})
|
|
||||||
|
|
||||||
db.GET("/value", func(c *gin.Context) {
|
baseP := req.NewPermission("config:base")
|
||||||
req.NewCtxWithGin(c).DontNeedToken().Handle(r.GetConfigValueByKey)
|
|
||||||
})
|
|
||||||
|
|
||||||
saveConfig := req.NewLogInfo("保存系统配置信息").WithSave(true)
|
reqs := [...]*req.Conf{
|
||||||
saveConfigP := req.NewPermission("config:save")
|
req.NewGet("", r.Configs).RequiredPermission(baseP),
|
||||||
db.POST("", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).
|
// 获取指定配置key对应的值
|
||||||
WithLog(saveConfig).
|
req.NewGet("/value", r.GetConfigValueByKey).DontNeedToken(),
|
||||||
WithRequiredPermission(saveConfigP).
|
|
||||||
Handle(r.SaveConfig)
|
req.NewPost("", r.SaveConfig).Log(req.NewLogSave("保存系统配置信息")).RequiredPermissionCode("config:save"),
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
req.BatchSetGroup(configG, reqs[:])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,48 +10,21 @@ import (
|
|||||||
|
|
||||||
func InitResourceRouter(router *gin.RouterGroup) {
|
func InitResourceRouter(router *gin.RouterGroup) {
|
||||||
r := &api.Resource{ResourceApp: application.GetResourceApp()}
|
r := &api.Resource{ResourceApp: application.GetResourceApp()}
|
||||||
db := router.Group("sys/resources")
|
rg := router.Group("sys/resources")
|
||||||
{
|
|
||||||
db.GET("", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).Handle(r.GetAllResourceTree)
|
|
||||||
})
|
|
||||||
|
|
||||||
db.GET(":id", func(c *gin.Context) {
|
reqs := [...]*req.Conf{
|
||||||
req.NewCtxWithGin(c).Handle(r.GetById)
|
req.NewGet("", r.GetAllResourceTree),
|
||||||
})
|
|
||||||
|
|
||||||
saveResource := req.NewLogInfo("保存资源").WithSave(true)
|
req.NewGet(":id", r.GetById),
|
||||||
srPermission := req.NewPermission("resource:add")
|
|
||||||
db.POST("", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithLog(saveResource).
|
|
||||||
WithRequiredPermission(srPermission).
|
|
||||||
Handle(r.SaveResource)
|
|
||||||
})
|
|
||||||
|
|
||||||
changeStatus := req.NewLogInfo("修改资源状态").WithSave(true)
|
req.NewPost("", r.SaveResource).Log(req.NewLogSave("保存资源")).RequiredPermissionCode("resource:add"),
|
||||||
csPermission := req.NewPermission("resource:changeStatus")
|
|
||||||
db.PUT(":id/:status", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithLog(changeStatus).
|
|
||||||
WithRequiredPermission(csPermission).
|
|
||||||
Handle(r.ChangeStatus)
|
|
||||||
})
|
|
||||||
|
|
||||||
sort := req.NewLogInfo("资源排序").WithSave(true)
|
req.NewPut(":id/:status", r.ChangeStatus).Log(req.NewLogSave("修改资源状态")).RequiredPermissionCode("resource:changeStatus"),
|
||||||
db.POST("sort", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithLog(sort).
|
|
||||||
Handle(r.Sort)
|
|
||||||
})
|
|
||||||
|
|
||||||
delResource := req.NewLogInfo("删除资源").WithSave(true)
|
req.NewPost("sort", r.Sort).Log(req.NewLogSave("资源排序")),
|
||||||
dePermission := req.NewPermission("resource:delete")
|
|
||||||
db.DELETE(":id", func(c *gin.Context) {
|
req.NewDelete(":id", r.DelResource).Log(req.NewLogSave("删除资源")).RequiredPermissionCode("resource:delete"),
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithLog(delResource).
|
|
||||||
WithRequiredPermission(dePermission).
|
|
||||||
Handle(r.DelResource)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
req.BatchSetGroup(rg, reqs[:])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,43 +13,21 @@ func InitRoleRouter(router *gin.RouterGroup) {
|
|||||||
RoleApp: application.GetRoleApp(),
|
RoleApp: application.GetRoleApp(),
|
||||||
ResourceApp: application.GetResourceApp(),
|
ResourceApp: application.GetResourceApp(),
|
||||||
}
|
}
|
||||||
db := router.Group("sys/roles")
|
rg := router.Group("sys/roles")
|
||||||
{
|
|
||||||
|
|
||||||
db.GET("", func(c *gin.Context) {
|
reqs := [...]*req.Conf{
|
||||||
req.NewCtxWithGin(c).Handle(r.Roles)
|
req.NewGet("", r.Roles),
|
||||||
})
|
|
||||||
|
|
||||||
saveRole := req.NewLogInfo("保存角色").WithSave(true)
|
req.NewPost("", r.SaveRole).Log(req.NewLogSave("保存角色")).RequiredPermissionCode("role:add"),
|
||||||
sPermission := req.NewPermission("role:add")
|
|
||||||
db.POST("", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).WithLog(saveRole).
|
|
||||||
WithRequiredPermission(sPermission).
|
|
||||||
Handle(r.SaveRole)
|
|
||||||
})
|
|
||||||
|
|
||||||
delRole := req.NewLogInfo("删除角色").WithSave(true)
|
req.NewDelete(":id", r.DelRole).Log(req.NewLogSave("删除角色")).RequiredPermissionCode("role:del"),
|
||||||
drPermission := req.NewPermission("role:del")
|
|
||||||
db.DELETE(":id", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).WithLog(delRole).
|
|
||||||
WithRequiredPermission(drPermission).
|
|
||||||
Handle(r.DelRole)
|
|
||||||
})
|
|
||||||
|
|
||||||
db.GET(":id/resourceIds", func(c *gin.Context) {
|
req.NewGet(":id/resourceIds", r.RoleResourceIds),
|
||||||
req.NewCtxWithGin(c).Handle(r.RoleResourceIds)
|
|
||||||
})
|
|
||||||
|
|
||||||
db.GET(":id/resources", func(c *gin.Context) {
|
req.NewGet(":id/resources", r.RoleResource),
|
||||||
req.NewCtxWithGin(c).Handle(r.RoleResource)
|
|
||||||
})
|
|
||||||
|
|
||||||
saveResource := req.NewLogInfo("保存角色资源").WithSave(true)
|
req.NewPost(":id/resources", r.SaveResource).Log(req.NewLogSave("保存角色资源")).RequiredPermissionCode("role:saveResources"),
|
||||||
srPermission := req.NewPermission("role:saveResources")
|
|
||||||
db.POST(":id/resources", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).WithLog(saveResource).
|
|
||||||
WithRequiredPermission(srPermission).
|
|
||||||
Handle(r.SaveResource)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
req.BatchSetGroup(rg, reqs[:])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,10 +12,7 @@ func InitSyslogRouter(router *gin.RouterGroup) {
|
|||||||
s := &api.Syslog{
|
s := &api.Syslog{
|
||||||
SyslogApp: application.GetSyslogApp(),
|
SyslogApp: application.GetSyslogApp(),
|
||||||
}
|
}
|
||||||
sys := router.Group("syslogs")
|
sysG := router.Group("syslogs")
|
||||||
{
|
|
||||||
sys.GET("", func(c *gin.Context) {
|
req.NewGet("", s.Syslogs).Group(sysG)
|
||||||
req.NewCtxWithGin(c).Handle(s.Syslogs)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,10 +140,11 @@ func (p *tagTreeAppImpl) CanAccess(accountId uint64, tagPath string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *tagTreeAppImpl) Delete(id uint64) {
|
func (p *tagTreeAppImpl) Delete(id uint64) {
|
||||||
biz.IsTrue(p.machineApp.Count(&machineentity.MachineQuery{TagId: id}) == 0, "请先删除该项目关联的机器信息")
|
tagIds := [1]uint64{id}
|
||||||
biz.IsTrue(p.redisApp.Count(&redisentity.RedisQuery{TagId: id}) == 0, "请先删除该项目关联的redis信息")
|
biz.IsTrue(p.machineApp.Count(&machineentity.MachineQuery{TagIds: tagIds[:]}) == 0, "请先删除该项目关联的机器信息")
|
||||||
biz.IsTrue(p.dbApp.Count(&dbentity.DbQuery{TagId: id}) == 0, "请先删除该项目关联的数据库信息")
|
biz.IsTrue(p.redisApp.Count(&redisentity.RedisQuery{TagIds: tagIds[:]}) == 0, "请先删除该项目关联的redis信息")
|
||||||
biz.IsTrue(p.mongoApp.Count(&mongoentity.MongoQuery{TagId: id}) == 0, "请先删除该项目关联的Mongo信息")
|
biz.IsTrue(p.dbApp.Count(&dbentity.DbQuery{TagIds: tagIds[:]}) == 0, "请先删除该项目关联的数据库信息")
|
||||||
|
biz.IsTrue(p.mongoApp.Count(&mongoentity.MongoQuery{TagIds: tagIds[:]}) == 0, "请先删除该项目关联的Mongo信息")
|
||||||
p.tagTreeRepo.Delete(id)
|
p.tagTreeRepo.Delete(id)
|
||||||
// 删除该标签关联的团队信息
|
// 删除该标签关联的团队信息
|
||||||
p.tagTreeTeamRepo.DeleteBy(&entity.TagTreeTeam{TagId: id})
|
p.tagTreeTeamRepo.DeleteBy(&entity.TagTreeTeam{TagId: id})
|
||||||
|
|||||||
@@ -15,37 +15,21 @@ func InitTagTreeRouter(router *gin.RouterGroup) {
|
|||||||
|
|
||||||
tagTree := router.Group("/tag-trees")
|
tagTree := router.Group("/tag-trees")
|
||||||
{
|
{
|
||||||
// 获取标签树列表
|
reqs := [...]*req.Conf{
|
||||||
tagTree.GET("", func(c *gin.Context) {
|
// 获取标签树列表
|
||||||
req.NewCtxWithGin(c).Handle(m.GetTagTree)
|
req.NewGet("", m.GetTagTree),
|
||||||
})
|
|
||||||
|
|
||||||
// 根据条件获取标签
|
// 根据条件获取标签
|
||||||
tagTree.GET("query", func(c *gin.Context) {
|
req.NewGet("query", m.ListByQuery),
|
||||||
req.NewCtxWithGin(c).Handle(m.ListByQuery)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 获取登录账号拥有的标签信息
|
// 获取登录账号拥有的标签信息
|
||||||
tagTree.GET("account-has", func(c *gin.Context) {
|
req.NewGet("account-has", m.GetAccountTags),
|
||||||
req.NewCtxWithGin(c).Handle(m.GetAccountTags)
|
|
||||||
})
|
|
||||||
|
|
||||||
saveTagTreeLog := req.NewLogInfo("标签树-保存信息").WithSave(true)
|
req.NewPost("", m.SaveTagTree).Log(req.NewLogSave("标签树-保存信息")).RequiredPermissionCode("tag:save"),
|
||||||
savePP := req.NewPermission("tag:save")
|
|
||||||
// 保存项目树下的环境信息
|
|
||||||
tagTree.POST("", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).WithLog(saveTagTreeLog).
|
|
||||||
WithRequiredPermission(savePP).
|
|
||||||
Handle(m.SaveTagTree)
|
|
||||||
})
|
|
||||||
|
|
||||||
delTagLog := req.NewLogInfo("标签树-删除信息").WithSave(true)
|
req.NewDelete(":id", m.DelTagTree).Log(req.NewLogSave("标签树-删除信息")).RequiredPermissionCode("tag:del"),
|
||||||
delPP := req.NewPermission("tag:del")
|
}
|
||||||
// 删除标签
|
|
||||||
tagTree.DELETE(":id", func(c *gin.Context) {
|
req.BatchSetGroup(tagTree, reqs[:])
|
||||||
req.NewCtxWithGin(c).WithLog(delTagLog).
|
|
||||||
WithRequiredPermission(delPP).
|
|
||||||
Handle(m.DelTagTree)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,64 +18,27 @@ func InitTeamRouter(router *gin.RouterGroup) {
|
|||||||
|
|
||||||
team := router.Group("/teams")
|
team := router.Group("/teams")
|
||||||
{
|
{
|
||||||
// 获取团队列表
|
reqs := [...]*req.Conf{
|
||||||
team.GET("", func(c *gin.Context) {
|
// 获取团队列表
|
||||||
req.NewCtxWithGin(c).Handle(m.GetTeams)
|
req.NewGet("", m.GetTeams),
|
||||||
})
|
|
||||||
|
|
||||||
saveTeamLog := req.NewLogInfo("团队-保存信息").WithSave(true)
|
req.NewPost("", m.SaveTeam).Log(req.NewLogSave("团队-保存信息")).RequiredPermissionCode("team:save"),
|
||||||
savePP := req.NewPermission("team:save")
|
|
||||||
// 保存项目团队信息
|
|
||||||
team.POST("", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).WithLog(saveTeamLog).
|
|
||||||
WithRequiredPermission(savePP).
|
|
||||||
Handle(m.SaveTeam)
|
|
||||||
})
|
|
||||||
|
|
||||||
delTeamLog := req.NewLogInfo("团队-删除信息").WithSave(true)
|
req.NewDelete(":id", m.DelTeam).Log(req.NewLogSave("团队-删除信息")).RequiredPermissionCode("team:del"),
|
||||||
delPP := req.NewPermission("team:del")
|
|
||||||
team.DELETE(":id", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).WithLog(delTeamLog).
|
|
||||||
WithRequiredPermission(delPP).
|
|
||||||
Handle(m.DelTeam)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 获取团队的成员信息列表
|
// 获取团队的成员信息列表
|
||||||
team.GET("/:id/members", func(c *gin.Context) {
|
req.NewGet("/:id/members", m.GetTeamMembers),
|
||||||
req.NewCtxWithGin(c).Handle(m.GetTeamMembers)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 保存团队成员
|
req.NewPost("/:id/members", m.SaveTeamMember).Log(req.NewLogSave("团队-新增成员")).RequiredPermissionCode("team:member:save"),
|
||||||
saveTeamMemLog := req.NewLogInfo("团队-新增成员").WithSave(true)
|
|
||||||
savePmP := req.NewPermission("team:member:save")
|
|
||||||
team.POST("/:id/members", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).WithLog(saveTeamMemLog).
|
|
||||||
WithRequiredPermission(savePmP).
|
|
||||||
Handle(m.SaveTeamMember)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 删除团队成员
|
req.NewDelete("/:id/members/:accountId", m.DelTeamMember).Log(req.NewLogSave("团队-删除成员")).RequiredPermissionCode("team:member:del"),
|
||||||
delTeamMemLog := req.NewLogInfo("团队-删除成员").WithSave(true)
|
|
||||||
savePmdP := req.NewPermission("team:member:del")
|
|
||||||
team.DELETE("/:id/members/:accountId", func(c *gin.Context) {
|
|
||||||
req.NewCtxWithGin(c).WithLog(delTeamMemLog).
|
|
||||||
WithRequiredPermission(savePmdP).
|
|
||||||
Handle(m.DelTeamMember)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 获取团队关联的标签id列表
|
// 获取团队关联的标签id列表
|
||||||
team.GET("/:id/tags", func(c *gin.Context) {
|
req.NewGet("/:id/tags", m.GetTagIds),
|
||||||
req.NewCtxWithGin(c).Handle(m.GetTagIds)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 保存团队标签关联信息
|
req.NewPost("/:id/tags", m.SaveTags).Log(req.NewLogSave("团队-保存标签关联信息")).RequiredPermissionCode("team:tag:save"),
|
||||||
saveTeamTagLog := req.NewLogInfo("团队-保存标签关联信息").WithSave(true)
|
}
|
||||||
saveTeamTagP := req.NewPermission("team:tag:save")
|
|
||||||
team.POST("/:id/tags", func(c *gin.Context) {
|
req.BatchSetGroup(team, reqs[:])
|
||||||
req.NewCtxWithGin(c).
|
|
||||||
WithLog(saveTeamTagLog).
|
|
||||||
WithRequiredPermission(saveTeamTagP).
|
|
||||||
Handle(m.SaveTags)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"mayfly-go/pkg/biz"
|
"mayfly-go/pkg/biz"
|
||||||
"mayfly-go/pkg/global"
|
"mayfly-go/pkg/global"
|
||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
|
"mayfly-go/pkg/utils"
|
||||||
"net/http"
|
"net/http"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -13,16 +14,36 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// 绑定并校验请求结构体参数
|
// 绑定并校验请求结构体参数
|
||||||
func BindJsonAndValid(g *gin.Context, data any) {
|
func BindJsonAndValid[T any](g *gin.Context, data T) T {
|
||||||
if err := g.ShouldBindJSON(data); err != nil {
|
if err := g.ShouldBindJSON(data); err != nil {
|
||||||
panic(biz.NewBizErr(err.Error()))
|
panic(biz.NewBizErr(err.Error()))
|
||||||
|
} else {
|
||||||
|
return data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 绑定查询字符串到
|
// 绑定请求体中的json至form结构体,并拷贝至另一结构体
|
||||||
func BindQuery(g *gin.Context, data any) {
|
func BindJsonAndCopyTo[T any](g *gin.Context, form any, toStruct T) T {
|
||||||
if err := g.ShouldBindQuery(data); err != nil {
|
BindJsonAndValid(g, form)
|
||||||
|
utils.Copy(toStruct, form)
|
||||||
|
return toStruct
|
||||||
|
}
|
||||||
|
|
||||||
|
// 绑定查询字符串到指定结构体
|
||||||
|
func BindQuery[T any](g *gin.Context, data T) T {
|
||||||
|
if err := g.BindQuery(data); err != nil {
|
||||||
panic(biz.NewBizErr(err.Error()))
|
panic(biz.NewBizErr(err.Error()))
|
||||||
|
} else {
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 绑定查询字符串到指定结构体,并将分页信息也返回
|
||||||
|
func BindQueryAndPage[T any](g *gin.Context, data T) (T, *model.PageParam) {
|
||||||
|
if err := g.BindQuery(data); err != nil {
|
||||||
|
panic(biz.NewBizErr(err.Error()))
|
||||||
|
} else {
|
||||||
|
return data, GetPageParam(g)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
85
server/pkg/req/conf.go
Normal file
85
server/pkg/req/conf.go
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
package req
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 请求配置,如是否需要权限,日志信息等配置
|
||||||
|
type Conf struct {
|
||||||
|
method string
|
||||||
|
path string
|
||||||
|
handler HandlerFunc // 请求处理函数
|
||||||
|
|
||||||
|
requiredPermission *Permission // 需要的权限信息,默认为nil,需要校验token
|
||||||
|
logInfo *LogInfo // 日志相关信息
|
||||||
|
noRes bool // 无需返回结果,即文件下载等
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(method, path string, handler HandlerFunc) *Conf {
|
||||||
|
return &Conf{method: method, path: path, handler: handler, noRes: false}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPost(path string, handler HandlerFunc) *Conf {
|
||||||
|
return New("POST", path, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGet(path string, handler HandlerFunc) *Conf {
|
||||||
|
return New("GET", path, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPut(path string, handler HandlerFunc) *Conf {
|
||||||
|
return New("PUT", path, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDelete(path string, handler HandlerFunc) *Conf {
|
||||||
|
return New("DELETE", path, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Conf) ToGinHFunc() gin.HandlerFunc {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
NewCtxWithGin(c).WithConf(r).Handle(r.handler)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 调用该方法设置请求描述,则默认记录日志,并不记录响应结果
|
||||||
|
func (r *Conf) Log(li *LogInfo) *Conf {
|
||||||
|
r.logInfo = li
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置请求上下文需要的权限信息
|
||||||
|
func (r *Conf) RequiredPermission(permission *Permission) *Conf {
|
||||||
|
r.requiredPermission = permission
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置请求上下文需要的权限信息
|
||||||
|
func (r *Conf) RequiredPermissionCode(code string) *Conf {
|
||||||
|
r.RequiredPermission(NewPermission(code))
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
// 不需要token校验
|
||||||
|
func (r *Conf) DontNeedToken() *Conf {
|
||||||
|
r.requiredPermission = &Permission{NeedToken: false}
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
// 没有响应结果,即文件下载等
|
||||||
|
func (r *Conf) NoRes() *Conf {
|
||||||
|
r.noRes = true
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
// 注册至group
|
||||||
|
func (r *Conf) Group(gr *gin.RouterGroup) *Conf {
|
||||||
|
gr.Handle(r.method, r.path, r.ToGinHFunc())
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
// 批量注册至group
|
||||||
|
func BatchSetGroup(gr *gin.RouterGroup, reqs []*Conf) {
|
||||||
|
for _, req := range reqs {
|
||||||
|
req.Group(gr)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,34 +19,35 @@ func SetSaveLogFunc(sl SaveLogFunc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type LogInfo struct {
|
type LogInfo struct {
|
||||||
LogResp bool // 是否记录返回结果
|
|
||||||
Description string // 请求描述
|
Description string // 请求描述
|
||||||
Save bool // 是否保存日志
|
|
||||||
|
LogResp bool // 是否记录返回结果
|
||||||
|
save bool // 是否保存日志
|
||||||
}
|
}
|
||||||
|
|
||||||
// 新建日志信息
|
// 新建日志信息,默认不保存该日志
|
||||||
func NewLogInfo(description string) *LogInfo {
|
func NewLog(description string) *LogInfo {
|
||||||
return &LogInfo{Description: description, LogResp: false}
|
return &LogInfo{Description: description, LogResp: false, save: false}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 是否记录返回结果
|
// 新建日志信息,并且需要保存该日志信息
|
||||||
func (i *LogInfo) WithLogResp(logResp bool) *LogInfo {
|
func NewLogSave(description string) *LogInfo {
|
||||||
i.LogResp = logResp
|
return &LogInfo{Description: description, LogResp: false, save: true}
|
||||||
return i
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 是否保存日志
|
// 记录返回结果
|
||||||
func (i *LogInfo) WithSave(saveLog bool) *LogInfo {
|
func (i *LogInfo) WithLogResp() *LogInfo {
|
||||||
i.Save = saveLog
|
i.LogResp = true
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
func LogHandler(rc *Ctx) error {
|
func LogHandler(rc *Ctx) error {
|
||||||
li := rc.LogInfo
|
if rc.Conf == nil || rc.Conf.logInfo == nil {
|
||||||
if li == nil {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
li := rc.Conf.logInfo
|
||||||
|
|
||||||
lfs := logrus.Fields{}
|
lfs := logrus.Fields{}
|
||||||
if la := rc.LoginAccount; la != nil {
|
if la := rc.LoginAccount; la != nil {
|
||||||
lfs["uid"] = la.Id
|
lfs["uid"] = la.Id
|
||||||
@@ -57,7 +58,7 @@ func LogHandler(rc *Ctx) error {
|
|||||||
lfs[req.Method] = req.URL.Path
|
lfs[req.Method] = req.URL.Path
|
||||||
|
|
||||||
// 如果需要保存日志,并且保存日志处理函数存在则执行保存日志函数
|
// 如果需要保存日志,并且保存日志处理函数存在则执行保存日志函数
|
||||||
if li.Save && saveLog != nil {
|
if li.save && saveLog != nil {
|
||||||
go saveLog(rc)
|
go saveLog(rc)
|
||||||
}
|
}
|
||||||
if err := rc.Err; err != nil {
|
if err := rc.Err; err != nil {
|
||||||
@@ -69,20 +70,21 @@ func LogHandler(rc *Ctx) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getLogMsg(rc *Ctx) string {
|
func getLogMsg(rc *Ctx) string {
|
||||||
msg := rc.LogInfo.Description + fmt.Sprintf(" ->%dms", rc.timed)
|
logInfo := rc.Conf.logInfo
|
||||||
|
msg := logInfo.Description + fmt.Sprintf(" ->%dms", rc.timed)
|
||||||
if !utils.IsBlank(rc.ReqParam) {
|
if !utils.IsBlank(rc.ReqParam) {
|
||||||
msg = msg + fmt.Sprintf("\n--> %s", utils.ToString(rc.ReqParam))
|
msg = msg + fmt.Sprintf("\n--> %s", utils.ToString(rc.ReqParam))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 返回结果不为空,则记录返回结果
|
// 返回结果不为空,则记录返回结果
|
||||||
if rc.LogInfo.LogResp && !utils.IsBlank(rc.ResData) {
|
if logInfo.LogResp && !utils.IsBlank(rc.ResData) {
|
||||||
msg = msg + fmt.Sprintf("\n<-- %s", utils.ToString(rc.ResData))
|
msg = msg + fmt.Sprintf("\n<-- %s", utils.ToString(rc.ResData))
|
||||||
}
|
}
|
||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
|
|
||||||
func getErrMsg(rc *Ctx, err any) string {
|
func getErrMsg(rc *Ctx, err any) string {
|
||||||
msg := rc.LogInfo.Description
|
msg := rc.Conf.logInfo.Description
|
||||||
if !utils.IsBlank(rc.ReqParam) {
|
if !utils.IsBlank(rc.ReqParam) {
|
||||||
msg = msg + fmt.Sprintf("\n--> %s", utils.ToString(rc.ReqParam))
|
msg = msg + fmt.Sprintf("\n--> %s", utils.ToString(rc.ReqParam))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,10 @@ func PermissionHandler(rc *Ctx) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
permission := rc.RequiredPermission
|
var permission *Permission
|
||||||
|
if rc.Conf != nil {
|
||||||
|
permission = rc.Conf.requiredPermission
|
||||||
|
}
|
||||||
// 如果需要的权限信息不为空,并且不需要token,则不返回错误,继续后续逻辑
|
// 如果需要的权限信息不为空,并且不需要token,则不返回错误,继续后续逻辑
|
||||||
if permission != nil && !permission.NeedToken {
|
if permission != nil && !permission.NeedToken {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -14,18 +14,14 @@ import (
|
|||||||
type HandlerFunc func(*Ctx)
|
type HandlerFunc func(*Ctx)
|
||||||
|
|
||||||
type Ctx struct {
|
type Ctx struct {
|
||||||
GinCtx *gin.Context // gin context
|
Conf *Conf // 请求配置
|
||||||
|
|
||||||
RequiredPermission *Permission // 需要的权限信息,默认为nil,需要校验token
|
GinCtx *gin.Context // gin context
|
||||||
LoginAccount *model.LoginAccount // 登录账号信息,只有校验token后才会有值
|
LoginAccount *model.LoginAccount // 登录账号信息,只有校验token后才会有值
|
||||||
|
ReqParam any // 请求参数,主要用于记录日志
|
||||||
LogInfo *LogInfo // 日志相关信息
|
ResData any // 响应结果
|
||||||
ReqParam any // 请求参数,主要用于记录日志
|
Err any // 请求错误
|
||||||
ResData any // 响应结果
|
timed int64 // 执行时间
|
||||||
Err any // 请求错误
|
|
||||||
|
|
||||||
timed int64 // 执行时间
|
|
||||||
NoRes bool // 无需返回结果,即文件下载等
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rc *Ctx) Handle(handler HandlerFunc) {
|
func (rc *Ctx) Handle(handler HandlerFunc) {
|
||||||
@@ -54,38 +50,46 @@ func (rc *Ctx) Handle(handler HandlerFunc) {
|
|||||||
begin := time.Now()
|
begin := time.Now()
|
||||||
handler(rc)
|
handler(rc)
|
||||||
rc.timed = time.Since(begin).Milliseconds()
|
rc.timed = time.Since(begin).Milliseconds()
|
||||||
if !rc.NoRes {
|
if rc.Conf == nil || !rc.Conf.noRes {
|
||||||
ginx.SuccessRes(ginCtx, rc.ResData)
|
ginx.SuccessRes(ginCtx, rc.ResData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rc *Ctx) Download(reader io.Reader, filename string) {
|
func (rc *Ctx) Download(reader io.Reader, filename string) {
|
||||||
rc.NoRes = true
|
|
||||||
ginx.Download(rc.GinCtx, reader, filename)
|
ginx.Download(rc.GinCtx, reader, filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (rc *Ctx) WithConf(conf *Conf) *Ctx {
|
||||||
|
rc.Conf = conf
|
||||||
|
return rc
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置请求上下文需要的权限信息
|
||||||
|
func (rc *Ctx) WithRequiredPermission(permission *Permission) *Ctx {
|
||||||
|
if rc.Conf == nil {
|
||||||
|
rc.Conf = new(Conf)
|
||||||
|
}
|
||||||
|
rc.Conf.requiredPermission = permission
|
||||||
|
return rc
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置请求日志信息
|
||||||
|
func (rc *Ctx) WithLog(logInfo *LogInfo) *Ctx {
|
||||||
|
if rc.Conf == nil {
|
||||||
|
rc.Conf = new(Conf)
|
||||||
|
}
|
||||||
|
rc.Conf.logInfo = logInfo
|
||||||
|
return rc
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rc *Ctx) GetLogInfo() *LogInfo {
|
||||||
|
return rc.Conf.logInfo
|
||||||
|
}
|
||||||
|
|
||||||
func NewCtxWithGin(g *gin.Context) *Ctx {
|
func NewCtxWithGin(g *gin.Context) *Ctx {
|
||||||
return &Ctx{GinCtx: g}
|
return &Ctx{GinCtx: g}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 调用该方法设置请求描述,则默认记录日志,并不记录响应结果
|
|
||||||
func (r *Ctx) WithLog(li *LogInfo) *Ctx {
|
|
||||||
r.LogInfo = li
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置请求上下文需要的权限信息
|
|
||||||
func (r *Ctx) WithRequiredPermission(permission *Permission) *Ctx {
|
|
||||||
r.RequiredPermission = permission
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
// 不需要token校验
|
|
||||||
func (r *Ctx) DontNeedToken() *Ctx {
|
|
||||||
r.RequiredPermission = &Permission{NeedToken: false}
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理器拦截器函数
|
// 处理器拦截器函数
|
||||||
type HandlerInterceptorFunc func(*Ctx) error
|
type HandlerInterceptorFunc func(*Ctx) error
|
||||||
type HandlerInterceptors []HandlerInterceptorFunc
|
type HandlerInterceptors []HandlerInterceptorFunc
|
||||||
|
|||||||
Reference in New Issue
Block a user