refactor: 后端包结构重构、去除无用的文件

This commit is contained in:
meilin.huang
2022-06-02 17:41:11 +08:00
parent 51d06ab206
commit b2dc9dff0b
234 changed files with 749 additions and 816 deletions

View File

@@ -0,0 +1,94 @@
package router
import (
"mayfly-go/internal/devops/api"
"mayfly-go/internal/devops/application"
sysApplication "mayfly-go/internal/sys/application"
"mayfly-go/pkg/ctx"
"github.com/gin-gonic/gin"
)
func InitDbRouter(router *gin.RouterGroup) {
db := router.Group("dbs")
{
d := &api.Db{
DbApp: application.DbApp,
MsgApp: sysApplication.MsgApp,
ProjectApp: application.ProjectApp,
}
// 获取所有数据库列表
db.GET("", func(c *gin.Context) {
rc := ctx.NewReqCtxWithGin(c)
rc.Handle(d.Dbs)
})
saveDb := ctx.NewLogInfo("保存数据库信息")
db.POST("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).
WithLog(saveDb).
Handle(d.Save)
})
deleteDb := ctx.NewLogInfo("删除数据库信息")
db.DELETE(":dbId", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).
WithLog(deleteDb).
Handle(d.DeleteDb)
})
db.GET(":dbId/t-infos", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(d.TableInfos)
})
db.GET(":dbId/t-index", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(d.TableIndex)
})
db.GET(":dbId/t-create-ddl", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(d.GetCreateTableDdl)
})
// db.GET(":dbId/exec-sql", controllers.SelectData)
db.GET(":dbId/exec-sql", func(g *gin.Context) {
rc := ctx.NewReqCtxWithGin(g).WithLog(ctx.NewLogInfo("执行Sql语句"))
rc.Handle(d.ExecSql)
})
db.POST(":dbId/exec-sql-file", func(g *gin.Context) {
rc := ctx.NewReqCtxWithGin(g).WithLog(ctx.NewLogInfo("执行Sql文件"))
rc.Handle(d.ExecSqlFile)
})
db.GET(":dbId/t-metadata", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(d.TableMA)
})
db.GET(":dbId/c-metadata", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(d.ColumnMA)
})
db.GET(":dbId/hint-tables", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(d.HintTables)
})
/** db sql相关接口 */
db.POST(":dbId/sql", func(c *gin.Context) {
rc := ctx.NewReqCtxWithGin(c)
rc.Handle(d.SaveSql)
})
db.GET(":dbId/sql", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(d.GetSql)
})
db.DELETE(":dbId/sql", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(d.DeleteSql)
})
db.GET(":dbId/sql-names", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(d.GetSqlNames)
})
}
}

View File

@@ -0,0 +1,69 @@
package router
import (
"mayfly-go/internal/devops/api"
"mayfly-go/internal/devops/application"
"mayfly-go/pkg/ctx"
"github.com/gin-gonic/gin"
)
func InitMachineRouter(router *gin.RouterGroup) {
m := &api.Machine{
MachineApp: application.MachineApp,
ProjectApp: application.ProjectApp,
}
machines := router.Group("machines")
{
machines.GET("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(m.Machines)
})
machines.GET(":machineId/stats", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(m.MachineStats)
})
machines.GET(":machineId/process", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(m.GetProcess)
})
// 终止进程
killProcessL := ctx.NewLogInfo("终止进程")
killProcessP := ctx.NewPermission("machine:killprocess")
machines.DELETE(":machineId/process", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).
WithLog(killProcessL).
WithRequiredPermission(killProcessP).
Handle(m.KillProcess)
})
saveMachine := ctx.NewLogInfo("保存机器信息")
machines.POST("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).
WithLog(saveMachine).
Handle(m.SaveMachine)
})
changeStatus := ctx.NewLogInfo("调整机器状态")
machines.PUT(":machineId/:status", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).
WithLog(changeStatus).
Handle(m.ChangeStatus)
})
delMachine := ctx.NewLogInfo("删除机器")
machines.DELETE(":machineId", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).
WithLog(delMachine).
Handle(m.DeleteMachine)
})
closeCli := ctx.NewLogInfo("关闭机器客户端")
machines.DELETE(":machineId/close-cli", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(closeCli).Handle(m.CloseCli)
})
machines.GET(":machineId/terminal", m.WsSSH)
}
}

View File

@@ -0,0 +1,80 @@
package router
import (
"mayfly-go/internal/devops/api"
"mayfly-go/internal/devops/application"
sysApplication "mayfly-go/internal/sys/application"
"mayfly-go/pkg/ctx"
"github.com/gin-gonic/gin"
)
func InitMachineFileRouter(router *gin.RouterGroup) {
machineFile := router.Group("machines")
{
mf := &api.MachineFile{
MachineFileApp: application.MachineFileApp,
MachineApp: application.MachineApp,
MsgApp: sysApplication.MsgApp,
}
// 获取指定机器文件列表
machineFile.GET(":machineId/files", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(mf.MachineFiles)
})
// 新增修改机器文件
addFileConf := ctx.NewLogInfo("新增机器文件配置")
afcP := ctx.NewPermission("machine:file:add")
machineFile.POST(":machineId/files", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(addFileConf).
WithRequiredPermission(afcP).
Handle(mf.SaveMachineFiles)
})
// 删除机器文件
delFileConf := ctx.NewLogInfo("删除机器文件配置")
dfcP := ctx.NewPermission("machine:file:del")
machineFile.DELETE(":machineId/files/:fileId", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(delFileConf).
WithRequiredPermission(dfcP).
Handle(mf.DeleteFile)
})
getContent := ctx.NewLogInfo("读取机器文件内容")
machineFile.GET(":machineId/files/:fileId/read", func(c *gin.Context) {
rc := ctx.NewReqCtxWithGin(c).WithLog(getContent)
rc.Handle(mf.ReadFileContent)
})
getDir := ctx.NewLogInfo("读取机器目录")
machineFile.GET(":machineId/files/:fileId/read-dir", func(c *gin.Context) {
rc := ctx.NewReqCtxWithGin(c).WithLog(getDir)
rc.Handle(mf.GetDirEntry)
})
writeFile := ctx.NewLogInfo("写入or下载文件内容")
wfP := ctx.NewPermission("machine:file:write")
machineFile.POST(":machineId/files/:fileId/write", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(writeFile).
WithRequiredPermission(wfP).
Handle(mf.WriteFileContent)
})
uploadFile := ctx.NewLogInfo("文件上传")
ufP := ctx.NewPermission("machine:file:upload")
machineFile.POST(":machineId/files/:fileId/upload", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(uploadFile).
WithRequiredPermission(ufP).
Handle(mf.UploadFile)
})
removeFile := ctx.NewLogInfo("删除文件or文件夹")
rfP := ctx.NewPermission("machine:file:rm")
machineFile.DELETE(":machineId/files/:fileId/remove", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(removeFile).
WithRequiredPermission(rfP).
Handle(mf.RemoveFile)
})
}
}

View File

@@ -0,0 +1,52 @@
package router
import (
"mayfly-go/internal/devops/api"
"mayfly-go/internal/devops/application"
"mayfly-go/pkg/ctx"
"github.com/gin-gonic/gin"
)
func InitMachineScriptRouter(router *gin.RouterGroup) {
machines := router.Group("machines")
{
ms := &api.MachineScript{
MachineScriptApp: application.MachineScriptApp,
MachineApp: application.MachineApp,
ProjectApp: application.ProjectApp,
}
// 获取指定机器脚本列表
machines.GET(":machineId/scripts", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(ms.MachineScripts)
})
saveMachienScriptLog := ctx.NewLogInfo("保存脚本")
smsP := ctx.NewPermission("machine:script:save")
// 保存脚本
machines.POST(":machineId/scripts", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(saveMachienScriptLog).
WithRequiredPermission(smsP).
Handle(ms.SaveMachineScript)
})
deleteLog := ctx.NewLogInfo("删除脚本")
dP := ctx.NewPermission("machine:script:del")
// 保存脚本
machines.DELETE(":machineId/scripts/:scriptId", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(deleteLog).
WithRequiredPermission(dP).
Handle(ms.DeleteMachineScript)
})
runLog := ctx.NewLogInfo("执行机器脚本")
rP := ctx.NewPermission("machine:script:run")
// 运行脚本
machines.GET(":machineId/scripts/:scriptId/run", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(runLog).
WithRequiredPermission(rP).
Handle(ms.RunMachineScript)
})
}
}

View File

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

View File

@@ -0,0 +1,83 @@
package router
import (
"mayfly-go/internal/devops/api"
"mayfly-go/internal/devops/application"
sys_applicaiton "mayfly-go/internal/sys/application"
"mayfly-go/pkg/ctx"
"github.com/gin-gonic/gin"
)
func InitProjectRouter(router *gin.RouterGroup) {
m := &api.Project{
ProjectApp: application.ProjectApp,
AccountApp: sys_applicaiton.AccountApp}
project := router.Group("/projects")
{
router.GET("/accounts/projects", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(m.GetProjectsByLoginAccount)
})
// 获取项目列表
project.GET("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(m.GetProjects)
})
saveProjectLog := ctx.NewLogInfo("保存项目信息")
savePP := ctx.NewPermission("project:save")
// 保存项目下的环境信息
project.POST("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(saveProjectLog).
WithRequiredPermission(savePP).
Handle(m.SaveProject)
})
delProjectLog := ctx.NewLogInfo("删除项目信息")
delPP := ctx.NewPermission("project:del")
// 删除项目
project.DELETE("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(delProjectLog).
WithRequiredPermission(delPP).
Handle(m.DelProject)
})
// 获取项目下的环境信息列表
project.GET("/:projectId/envs", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(m.GetProjectEnvs)
})
saveProjectEnvLog := ctx.NewLogInfo("新增项目环境信息")
savePeP := ctx.NewPermission("project:env:add")
// 保存项目下的环境信息
project.POST("/:projectId/envs", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(saveProjectEnvLog).
WithRequiredPermission(savePeP).
Handle(m.SaveProjectEnvs)
})
// 获取项目下的成员信息列表
project.GET("/:projectId/members", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(m.GetProjectMembers)
})
// 保存项目成员
saveProjectMemLog := ctx.NewLogInfo("新增项目成员")
savePmP := ctx.NewPermission("project:member:add")
project.POST("/:projectId/members", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(saveProjectMemLog).
WithRequiredPermission(savePmP).
Handle(m.SaveProjectMember)
})
// 删除项目成员
delProjectMemLog := ctx.NewLogInfo("删除项目成员")
savePmdP := ctx.NewPermission("project:member:del")
project.DELETE("/:projectId/members/:accountId", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(delProjectMemLog).
WithRequiredPermission(savePmdP).
Handle(m.DelProjectMember)
})
}
}

View File

@@ -0,0 +1,80 @@
package router
import (
"mayfly-go/internal/devops/api"
"mayfly-go/internal/devops/application"
"mayfly-go/pkg/ctx"
"github.com/gin-gonic/gin"
)
func InitRedisRouter(router *gin.RouterGroup) {
redis := router.Group("redis")
{
rs := &api.Redis{
RedisApp: application.RedisApp,
ProjectApp: application.ProjectApp,
}
// 获取redis list
redis.GET("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(rs.RedisList)
})
save := ctx.NewLogInfo("保存redis信息")
redis.POST("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(save).Handle(rs.Save)
})
delRedis := ctx.NewLogInfo("删除redis信息")
redis.DELETE(":id", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(delRedis).Handle(rs.DeleteRedis)
})
redis.GET(":id/info", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(rs.RedisInfo)
})
// 获取指定redis keys
redis.GET(":id/scan/:cursor/:count", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(rs.Scan)
})
// 删除key
deleteKeyL := ctx.NewLogInfo("redis删除key")
// deleteKey := ctx.NewPermission("project:save")
redis.DELETE(":id/key", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(deleteKeyL).Handle(rs.DeleteKey)
})
// 获取string类型值
redis.GET(":id/string-value", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(rs.GetStringValue)
})
// 设置string类型值
redis.POST(":id/string-value", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(rs.SetStringValue)
})
// 获取hash类型值
redis.GET(":id/hash-value", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(rs.GetHashValue)
})
// 设置hash类型值
redis.POST(":id/hash-value", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(rs.SetHashValue)
})
// 获取set类型值
redis.GET(":id/set-value", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(rs.GetSetValue)
})
// 设置set类型值
redis.POST(":id/set-value", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(rs.SetSetValue)
})
}
}