fix: goctl not compile on windows (#1500)
This commit is contained in:
7
tools/goctl/migrate/cancel+polyfill.go
Normal file
7
tools/goctl/migrate/cancel+polyfill.go
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
//go:build windows
|
||||||
|
// +build windows
|
||||||
|
|
||||||
|
package migrate
|
||||||
|
|
||||||
|
func cancelOnSignals() {
|
||||||
|
}
|
||||||
31
tools/goctl/migrate/cancel.go
Normal file
31
tools/goctl/migrate/cancel.go
Normal file
@@ -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)
|
||||||
|
}
|
||||||
@@ -10,16 +10,13 @@ import (
|
|||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/logrusorgru/aurora"
|
"github.com/logrusorgru/aurora"
|
||||||
"github.com/urfave/cli"
|
"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/console"
|
||||||
"github.com/zeromicro/go-zero/tools/goctl/util/ctx"
|
"github.com/zeromicro/go-zero/tools/goctl/util/ctx"
|
||||||
"github.com/zeromicro/go-zero/tools/goctl/vars"
|
"github.com/zeromicro/go-zero/tools/goctl/vars"
|
||||||
@@ -71,22 +68,7 @@ func rewriteImport(verbose bool) error {
|
|||||||
time.Sleep(200 * time.Millisecond)
|
time.Sleep(200 * time.Millisecond)
|
||||||
}
|
}
|
||||||
|
|
||||||
doneChan := syncx.NewDoneChan()
|
cancelOnSignals()
|
||||||
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)
|
|
||||||
|
|
||||||
wd, err := os.Getwd()
|
wd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user