diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 693267f..f832ec6 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -16,16 +16,10 @@ jobs: - name: Check out code into the Go module directory uses: actions/checkout@v1 - - name: Get dependencies - run: | - go get -v -t -d ./... - if [ -f Gopkg.toml ]; then - curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh - dep ensure - fi - - name: Run golangci-lint uses: golangci/golangci-lint-action@v1.2.1 - + with: + # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. + version: v1.26 - name: Build run: go build -v . diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..85e4d15 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,53 @@ +linters: + # please, do not use `enable-all`: it's deprecated and will be removed soon. + # inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint + disable-all: true + enable: + - bodyclose + - deadcode + - depguard + - dogsled + - dupl + - errcheck + - funlen + - goconst + - gocritic + - gocyclo + - gofmt + - goimports + - golint + - goprintffuncname + - gosimple + - govet + - ineffassign + - interfacer + - misspell + - nolintlint + - rowserrcheck + - scopelint + - staticcheck + - structcheck + - stylecheck + - typecheck + - unconvert + - unparam + - unused + - varcheck + - whitespace + +issues: + # Excluding configuration per-path, per-linter, per-text and per-source + exclude-rules: + - path: _test\.go + linters: + - gomnd + + # https://github.com/go-critic/go-critic/issues/926 + - linters: + - gocritic + text: "unnecessaryDefer:" + +linters-settings: + funlen: + lines: 66 + statements: 40 \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..c9da8eb --- /dev/null +++ b/go.mod @@ -0,0 +1,11 @@ +module github.com/silenceper/gowatch + +go 1.14 + +require ( + github.com/howeyc/fsnotify v0.9.0 + github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect + github.com/silenceper/log v0.0.0-20171204144354-e5ac7fa8a76a + gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect + gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..3f76568 --- /dev/null +++ b/go.sum @@ -0,0 +1,11 @@ +github.com/howeyc/fsnotify v0.9.0 h1:0gtV5JmOKH4A8SsFxG2BczSeXWWPvcMT0euZt5gDAxY= +github.com/howeyc/fsnotify v0.9.0/go.mod h1:41HzSPxBGeFRQKEEwgh49TRw/nKBsYZ2cF1OzPjSJsA= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= +github.com/silenceper/log v0.0.0-20171204144354-e5ac7fa8a76a/go.mod h1:nyN/YUSK3CgJjtNzm6dVTkcou+RYXNMP+XLSlzQu0m0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0 h1:POO/ycCATvegFmVuPpQzZFJ+pGZeX22Ufu6fibxDVjU= +gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa3CI79GS0ol3YnhVnKP89i0kNg= diff --git a/gowatch.go b/gowatch.go index 8add004..c648475 100644 --- a/gowatch.go +++ b/gowatch.go @@ -57,11 +57,10 @@ func NewWatcher(paths []string, files []string) { // Wait 1s before autobuild util there is no file change. scheduleTime = time.Now().Add(1 * time.Second) for { - time.Sleep(scheduleTime.Sub(time.Now())) + time.Sleep(time.Until(scheduleTime)) if time.Now().After(scheduleTime) { break } - return } Autobuild(files) @@ -83,7 +82,6 @@ func NewWatcher(paths []string, files []string) { os.Exit(2) } } - } // getFileModTime retuens unix timestamp of `os.File.ModTime` by given path. @@ -172,7 +170,7 @@ func Restart(appname string) { //Start start app func Start(appname string) { log.Infof("Restarting %s ...\n", appname) - if strings.Index(appname, "./") == -1 { + if !strings.HasPrefix(appname, "./") { appname = "./" + appname } @@ -182,7 +180,9 @@ func Start(appname string) { cmd.Args = append([]string{appname}, cfg.CmdArgs...) cmd.Env = append(os.Environ(), cfg.Envs...) log.Infof("Run %s", strings.Join(cmd.Args, " ")) - go cmd.Run() + go func() { + _ = cmd.Run() + }() log.Infof("%s is running...\n", appname) started <- true @@ -237,17 +237,16 @@ func readAppDirectories(directory string, paths *[]string) { continue } - if fileInfo.IsDir() == true && fileInfo.Name()[0] != '.' { + if fileInfo.IsDir() && fileInfo.Name()[0] != '.' { readAppDirectories(directory+"/"+fileInfo.Name(), paths) continue } - if useDirectory == true { + if useDirectory { continue } *paths = append(*paths, directory) useDirectory = true } - return } // If a file is excluded diff --git a/main.go b/main.go index 148ee23..ee7d119 100644 --- a/main.go +++ b/main.go @@ -93,10 +93,6 @@ func runApp() { } NewWatcher(paths, files) Autobuild(files) - for { - select { - case <-exit: - runtime.Goexit() - } - } + <-exit + runtime.Goexit() } diff --git a/vendor/vendor.json b/vendor/vendor.json deleted file mode 100644 index 06de7df..0000000 --- a/vendor/vendor.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "comment": "", - "ignore": "test", - "package": [ - { - "checksumSHA1": "ZxzYc1JwJ3U6kZbw/KGuPko5lSY=", - "path": "github.com/howeyc/fsnotify", - "revision": "f0c08ee9c60704c1879025f2ae0ff3e000082c13", - "revisionTime": "2015-10-03T19:46:02Z" - }, - { - "checksumSHA1": "vu02Mae/2hEatndbEFW3Z0rKVRs=", - "path": "github.com/silenceper/log", - "revision": "e5ac7fa8a76a863e90c8b624d5c2d4cab8e48394", - "revisionTime": "2017-12-04T14:43:54Z" - }, - { - "checksumSHA1": "MGk7cSnHqiL5soaovzgcJaNH3fc=", - "path": "gopkg.in/yaml.v1", - "revision": "9f9df34309c04878acc86042b16630b0f696e1de", - "revisionTime": "2014-09-24T16:16:07Z" - } - ], - "rootPath": "github.com/silenceper/gowatch" -} diff --git a/version.go b/version.go index e79edc4..f960901 100644 --- a/version.go +++ b/version.go @@ -2,7 +2,7 @@ package main import "fmt" -const version = "1.1" +const version = "1.3" func printVersion() { fmt.Println(version)