Skip to content

Commit

Permalink
Merge pull request #21 from silenceper/f-module
Browse files Browse the repository at this point in the history
add golangci-lint
  • Loading branch information
silenceper authored Jun 24, 2020
2 parents a42b5ec + 2e2cf9c commit 8e473a9
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 49 deletions.
12 changes: 3 additions & 9 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]

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 .
53 changes: 53 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
)
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
15 changes: 7 additions & 8 deletions gowatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -83,7 +82,6 @@ func NewWatcher(paths []string, files []string) {
os.Exit(2)
}
}

}

// getFileModTime retuens unix timestamp of `os.File.ModTime` by given path.
Expand Down Expand Up @@ -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
}

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ func runApp() {
}
NewWatcher(paths, files)
Autobuild(files)
for {
select {
case <-exit:
runtime.Goexit()
}
}
<-exit
runtime.Goexit()
}
25 changes: 0 additions & 25 deletions vendor/vendor.json

This file was deleted.

2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import "fmt"

const version = "1.1"
const version = "1.3"

func printVersion() {
fmt.Println(version)
Expand Down

0 comments on commit 8e473a9

Please sign in to comment.