From 8f46eab97739f8a81dd3b8fb33e184c90b707b3e Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Tue, 1 Feb 2022 13:58:08 +0800 Subject: [PATCH] fix: goctl not compile on windows (#1500) --- tools/goctl/migrate/cancel+polyfill.go | 7 ++++++ tools/goctl/migrate/cancel.go | 31 ++++++++++++++++++++++++++ tools/goctl/migrate/migrate.go | 20 +---------------- 3 files changed, 39 insertions(+), 19 deletions(-) create mode 100644 tools/goctl/migrate/cancel+polyfill.go create mode 100644 tools/goctl/migrate/cancel.go diff --git a/tools/goctl/migrate/cancel+polyfill.go b/tools/goctl/migrate/cancel+polyfill.go new file mode 100644 index 00000000..d5f2d543 --- /dev/null +++ b/tools/goctl/migrate/cancel+polyfill.go @@ -0,0 +1,7 @@ +//go:build windows +// +build windows + +package migrate + +func cancelOnSignals() { +} diff --git a/tools/goctl/migrate/cancel.go b/tools/goctl/migrate/cancel.go new file mode 100644 index 00000000..47968f1e --- /dev/null +++ b/tools/goctl/migrate/cancel.go @@ -0,0 +1,31 @@ +//go:build linux || darwin +// +build linux darwin + +package migrate + +import ( + "os" + "os/signal" + "syscall" + + "github.com/zeromicro/go-zero/core/syncx" + "github.com/zeromicro/go-zero/tools/goctl/util/console" +) + +func cancelOnSignals() { + doneChan := syncx.NewDoneChan() + defer doneChan.Close() + + go func(dc *syncx.DoneChan) { + c := make(chan os.Signal) + signal.Notify(c, syscall.SIGTERM, syscall.SIGKILL, syscall.SIGINT, syscall.SIGTSTP, syscall.SIGQUIT) + select { + case <-c: + console.Error(` +migrate failed, reason: "User Canceled"`) + os.Exit(0) + case <-dc.Done(): + return + } + }(doneChan) +} diff --git a/tools/goctl/migrate/migrate.go b/tools/goctl/migrate/migrate.go index 7a0bd1b2..24d0f524 100644 --- a/tools/goctl/migrate/migrate.go +++ b/tools/goctl/migrate/migrate.go @@ -10,16 +10,13 @@ import ( "io/fs" "io/ioutil" "os" - "os/signal" "path/filepath" "runtime" "strings" - "syscall" "time" "github.com/logrusorgru/aurora" "github.com/urfave/cli" - "github.com/zeromicro/go-zero/core/syncx" "github.com/zeromicro/go-zero/tools/goctl/util/console" "github.com/zeromicro/go-zero/tools/goctl/util/ctx" "github.com/zeromicro/go-zero/tools/goctl/vars" @@ -71,22 +68,7 @@ func rewriteImport(verbose bool) error { time.Sleep(200 * time.Millisecond) } - doneChan := syncx.NewDoneChan() - defer func() { - doneChan.Close() - }() - go func(dc *syncx.DoneChan) { - c := make(chan os.Signal) - signal.Notify(c, syscall.SIGTERM, syscall.SIGKILL, syscall.SIGINT, syscall.SIGTSTP, syscall.SIGQUIT) - select { - case <-c: - console.Error(` -migrate failed, reason: "User Canceled"`) - os.Exit(0) - case <-dc.Done(): - return - } - }(doneChan) + cancelOnSignals() wd, err := os.Getwd() if err != nil {