Skip to content

Commit 2725a3e

Browse files
authored
Merge pull request #28 from silenceper/f-golangci
fix golangci-lint
2 parents 07e4180 + e5ef272 commit 2725a3e

File tree

5 files changed

+35
-27
lines changed

5 files changed

+35
-27
lines changed

.golangci.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,12 @@ issues:
5050
linters-settings:
5151
funlen:
5252
lines: 66
53-
statements: 40
53+
statements: 40
54+
55+
issues:
56+
include:
57+
- EXC0002 # disable excluding of issues about comments from golint
58+
exclude-rules:
59+
- linters:
60+
- stylecheck
61+
text: "ST1000:"

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
gowatch is a command line tool that builds and (re)starts your go project everytime you save a Go or template file.
1010

11+
![gowatch](./screenshot/gowatch.png)
1112

1213
## Installation
1314
To install `gowatch` use the `go get` command:
@@ -33,7 +34,6 @@ Start gowatch:
3334
gowatch
3435
```
3536

36-
![gowatch](./screenshot/gowatch.png)
3737

3838
Gowatch will watch for file events, and every time you create/modify/delete a file it will build and restart the application,If `go build` returns an error, it will log it in stdout.
3939

config.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,31 @@ import (
1111
var configFile = "./gowatch.yml"
1212

1313
type config struct {
14-
//执行的app名字,默认当前目录文字
14+
// The name of the running app, the default current directory name
1515
AppName string `yaml:"appname"`
16-
//指定ouput执行的程序路径
16+
// Specify the program path for output execution
1717
Output string `yaml:"output"`
18-
//需要追加监听的文件后缀名字,默认是'.go'
18+
// Need to add watch file suffix name, the default is'.go',
1919
WatchExts []string `yaml:"watch_exts"`
20-
//需要追加监听的目录,默认是当前文件夹,
20+
// Need to add watch directory, the default is the current folder
2121
WatchPaths []string `yaml:"watch_paths"`
22-
//build前额外执行的命令
22+
// Additional commands executed before the build command
2323
PrevBuildCmds []string `yaml:"prev_build_cmds"`
24-
//执行时的额外参数
24+
// Extra parameters when running the application
2525
CmdArgs []string `yaml:"cmd_args"`
26-
//构建时的额外参数
26+
// Additional parameters during build
2727
BuildArgs []string `yaml:"build_args"`
28-
//执行时追加的环境变量
28+
// Environment variables added when running the application
2929
Envs []string `yaml:"envs"`
30-
//vendor 目录下的文件是否也监听
30+
// Specify whether the files in the vendor directory are also watched
3131
VendorWatch bool `yaml:"vendor_watch"`
32-
//不需要监听的目录
32+
// Specify a directory that does not require watch
3333
ExcludedPaths []string `yaml:"excluded_paths"`
34-
//需要编译的包或文件,优先使用-p参数
34+
// For packages or files that need to be compiled, use the -p parameter first
3535
BuildPkg string `yaml:"build_pkg"`
36-
//在go build 时期接收的-tags参数
36+
// -tags parameter accepted during go build
3737
BuildTags string `yaml:"build_tags"`
38-
//程序是否自动运行
38+
// Specify whether the program runs automatically
3939
DisableRun bool `yaml:"disable_run"`
4040
}
4141

gowatch.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var (
2222
scheduleTime time.Time
2323
)
2424

25-
//NewWatcher new watcher
25+
// NewWatcher new watcher
2626
func NewWatcher(paths []string, files []string) {
2727
watcher, err := fsnotify.NewWatcher()
2828
if err != nil {
@@ -46,7 +46,7 @@ func NewWatcher(paths []string, files []string) {
4646

4747
mt := getFileModTime(e.Name)
4848
if t := eventTime[e.Name]; mt == t {
49-
//log.Infof("[SKIP] # %s #\n", e.String())
49+
// log.Infof("[SKIP] # %s #\n", e.String())
5050
isbuild = false
5151
}
5252

@@ -86,7 +86,7 @@ func NewWatcher(paths []string, files []string) {
8686

8787
// getFileModTime retuens unix timestamp of `os.File.ModTime` by given path.
8888
func getFileModTime(path string) int64 {
89-
path = strings.Replace(path, "\\", "/", -1)
89+
path = strings.ReplaceAll(path, "\\", "/")
9090
f, err := os.Open(path)
9191
if err != nil {
9292
log.Errorf("Fail to open file[ %s ]\n", err)
@@ -103,7 +103,7 @@ func getFileModTime(path string) int64 {
103103
return fi.ModTime().Unix()
104104
}
105105

106-
//Autobuild auto build
106+
// Autobuild auto build
107107
func Autobuild(files []string) {
108108
state.Lock()
109109
defer state.Unlock()
@@ -159,7 +159,7 @@ func Autobuild(files []string) {
159159
}
160160
}
161161

162-
//Kill kill process
162+
// Kill kill process
163163
func Kill() {
164164
defer func() {
165165
if e := recover(); e != nil {
@@ -174,14 +174,14 @@ func Kill() {
174174
}
175175
}
176176

177-
//Restart restart app
177+
// Restart restart app
178178
func Restart(appname string) {
179-
//log.Debugf("kill running process")
179+
// log.Debugf("kill running process")
180180
Kill()
181181
go Start(appname)
182182
}
183183

184-
//Start start app
184+
// Start start app
185185
func Start(appname string) {
186186
log.Infof("Restarting %s ...\n", appname)
187187
if !strings.HasPrefix(appname, "./") {

main.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func main() {
4545
cfg = parseConfig()
4646
currpath, _ = os.Getwd()
4747
if cfg.AppName == "" {
48-
//app名默认取目录名
48+
// The app name defaults to the directory name
4949
if output == "" {
5050
cfg.AppName = path.Base(currpath)
5151
} else {
@@ -57,7 +57,7 @@ func main() {
5757
cfg.Output = output
5858
}
5959

60-
//如果未指定output则为"./appname"
60+
// If output is not specified, it is "./appname"
6161
if cfg.Output == "" {
6262
outputExt := ""
6363
if runtime.GOOS == "windows" {
@@ -70,7 +70,7 @@ func main() {
7070
cfg.CmdArgs = strings.Split(cmdArgs, ",")
7171
}
7272

73-
//监听的文件后缀
73+
// File suffix to be watched
7474
cfg.WatchExts = append(cfg.WatchExts, ".go")
7575

7676
runApp()
@@ -79,7 +79,7 @@ func main() {
7979
func runApp() {
8080
var paths []string
8181
readAppDirectories(currpath, &paths)
82-
//除了当前目录,增加额外监听的目录
82+
// In addition to the current directory, add additional watch directories
8383
for _, path := range cfg.WatchPaths {
8484
readAppDirectories(path, &paths)
8585
}

0 commit comments

Comments
 (0)