From 0366c23d2676bafc26d39d3dcd76be4ccc0099f6 Mon Sep 17 00:00:00 2001 From: 3343780376 <3343780376@qq.com> Date: Sun, 15 Jan 2023 11:12:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8B=89=E5=BA=93=E6=97=B6=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=89=A7=E8=A1=8Cgo=20mod=20tidy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/subscription/manager.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/service/subscription/manager.go b/service/subscription/manager.go index c5fd597..3ed0a5e 100644 --- a/service/subscription/manager.go +++ b/service/subscription/manager.go @@ -1,6 +1,7 @@ package subscription import ( + "context" "errors" "fmt" "github.com/google/uuid" @@ -135,7 +136,7 @@ func downloadPublicRepo(subscriptions *models.Subscriptions) error { } func addScripts(subscriptions *models.Subscriptions) { - file, _ := os.OpenFile(subscriptions.LogPath, os.O_CREATE|os.O_RDWR, 0666) + file, _ := os.OpenFile(subscriptions.LogPath, os.O_RDWR|os.O_APPEND, 0666) defer file.Close() var extensions []string if subscriptions.Extensions != "" { @@ -152,7 +153,12 @@ func addScripts(subscriptions *models.Subscriptions) { for _, crontab := range crontabs { cronMap[crontab.Command] = crontab } + isGoMod := false for _, entry := range dir { + + if entry.Name() == "go.mod" { + isGoMod = true + } // 判断文件后缀 if !utils.In(strings.TrimPrefix(filepath.Ext(entry.Name()), "."), extensions) { if !entry.IsDir() { @@ -200,6 +206,23 @@ func addScripts(subscriptions *models.Subscriptions) { models.DeleteCron(m.Id) } } + if isGoMod { + file.WriteString("检测到go模块,开始自动下载golang依赖!!") + cancelChan := make(chan int, 1) + ctx := context.WithValue(context.Background(), "cancel", cancelChan) + utils.RunWithOption(ctx, &utils.RunOption{ + Command: "go mod tidy", + Env: map[string]string{}, + OnStart: func(ctx context.Context) { + + }, + OnEnd: func(ctx context.Context) { + + }, + LogFile: file, + CmdDir: path.Join("data", "scripts", subscriptions.Alias), + }) + } } func getSubCron(filePath string) (name string, cron string, err error) {