mirror of
				https://gitee.com/dromara/mayfly-go
				synced 2025-11-04 16:30:25 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			53 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			53 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
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)
 | 
						|
		})
 | 
						|
	}
 | 
						|
}
 |