silenceper / gowatch Goto Github PK
View Code? Open in Web Editor NEW🚀 gowatch is a command line tool that builds and (re)starts your go project everytime you save a Go or template file.
License: MIT License
🚀 gowatch is a command line tool that builds and (re)starts your go project everytime you save a Go or template file.
License: MIT License
If I do go get for this package, I get the error shown below. This was working until recently.
❯ docker run -ti --entrypoint /bin/sh golang:1.14.2-alpine
/go # apk update && apk add git
/go # go get -u github.com/silenceper/gowatch
unrecognized import path "io/fs": import path does not begin with hostname
Note that it does seem to work with 1.16.15-alpine.
When I try to use this tool in a Linux Docker amd64 VM hosted on Mac OS with an M1 (amd64), I get a failure that inotify_init()
fails. This is due to the old fsnotify dependency; updating this dependency to the latest version would fix this. I'll open a PR that should fix the problem:
大部分时间我们都是在debug,而不是构建代码
我使用vue3+go-fiber开发,之前使用air热更新,但是air存在屏蔽日志输出和卡死进程的问题,换了gowatch后一切正常。唯一不足的是需要手动创建一个gowatch.yml文件,希望增加gowatch init命令,用于初始化一个gowatch.yml文件。
感谢作者
silenceper你好,我按照你的说明安装了gowatch,发现根本没法直接使用gowatch命令,麻烦具体说明下,我用的是centos7系统
gowatch.yml文件中
例如
cmd_args:
- -ldflags
- "-s -w"
经过代码阅读
我发现在gowatch.go文件的122行后增加
args = append(args, cfg.CmdArgs...)
重新编译后功能修复
另外,似乎envs等属性也没有被加载,不过我暂时没有用到所以没试
我没仔细阅读代码,也许有更好的修复方法
如题
I think the problem is with go-critic .
Windows PowerShell
版权所有 (C) 2016 Microsoft Corporation。保留所有权利。PS D:\WWW\blog> go get github.com/silenceper/gowatch
# cd .; git clone https://github.com/nestgo/log C:\Users\33318\go\src\github.com\nestgo\log
Cloning into 'C:\Users\33318\go\src\github.com\nestgo\log'...
remote: Repository not found.
fatal: repository 'https://github.com/nestgo/log/' not found
package github.com/nestgo/log: exit status 128
PS D:\WWW\blog>
I have a requirement to listen to tmpl
files, which are in the templates
folder, but I set the watch_path
, but it doesn't seem to work
watch_paths:
- templates/*
比如 gowatch -args aa=bb
在配置文件gowach.yml 中能够 引用 ${aa} 获取到bb
可以做个Docker容器,或者完善一下Docker部分的文档(方便一下使用docker作为开发的开发者呗),这里放一个我自己用的dockerfile供参考(
感谢作者啦!
# Use Dockerfile to Build Dev Environment(support hot reload)
# Base image
FROM golang:1.22
# Set the working directory
# --------------------
WORKDIR /app
# COPY file
# --------------------
COPY go.mod .
COPY go.sum .
# Config Proxy
# --------------------
RUN go env -w GO111MODULE=on && go env -w GOPROXY=https://goproxy.cn,direct
# https://mirrors.aliyun.com/goproxy/,direct
# Install dependences
# --------------------
RUN go mod download
RUN export GOPATH=/go && go install github.com/silenceper/gowatch@latest && ls -al /go/bin
# go install github.com/silenceper/gowatch@latest
# Add /go/bin to PATH
# --------------------
ENV PATH=/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/go/bin
环境:
操作系统:Win10专业版 x64
Go版本: go1.14 windows/amd64
配置文件内容:
# 当前目录执行下生成的可执行文件的名字,默认是当前目录名
appname: "demo"
# 指定编译后的目标文件目录
output: ./cmd
# 需要追加监听的文件名后缀,默认只有'.go'文件
watch_exts:
# 需要监听的目录,默认只有当前目录
watch_paths:
# 在执行命令时,需要增加的其他参数
cmd_args:
- -conf="D:\GoCode\src\kratos-demo\configs"
# 在构建命令时,需要增加的其他参数
build_args:
# 需要增加环境变量,默认已加载当前环境变量
envs:
# 是否监听 ‘vendor’ 文件夹下的文件改变
vendor_watch: false
# 不需要监听的目录名字
excluded_paths:
# main 包路径,也可以是单个文件,多个文件使用逗号分隔
build_pkg: "./cmd/main.go"
# build tags
build_tags: ""
# 是否禁止自动运行
disable_run: false
运行信息:
2020/03/18 16:34:09 gowatch.go:77: [32m[INFO][0m Initializing watcher...
2020/03/18 16:34:09 gowatch.go:79: [32m[INFO][0m Directory( D:\GoCode\src\kratos-demo )
2020/03/18 16:34:09 gowatch.go:79: [32m[INFO][0m Directory( D:\GoCode\src\kratos-demo/api )
2020/03/18 16:34:09 gowatch.go:79: [32m[INFO][0m Directory( D:\GoCode\src\kratos-demo/cmd )
2020/03/18 16:34:09 gowatch.go:79: [32m[INFO][0m Directory( D:\GoCode\src\kratos-demo/cmd/tmp )
2020/03/18 16:34:09 gowatch.go:79: [32m[INFO][0m Directory( D:\GoCode\src\kratos-demo/configs )
2020/03/18 16:34:09 gowatch.go:79: [32m[INFO][0m Directory( D:\GoCode\src\kratos-demo/internal/dao )
2020/03/18 16:34:09 gowatch.go:79: [32m[INFO][0m Directory( D:\GoCode\src\kratos-demo/internal/di )
2020/03/18 16:34:09 gowatch.go:79: [32m[INFO][0m Directory( D:\GoCode\src\kratos-demo/internal/model )
2020/03/18 16:34:09 gowatch.go:79: [32m[INFO][0m Directory( D:\GoCode\src\kratos-demo/internal/server/grpc )
2020/03/18 16:34:09 gowatch.go:79: [32m[INFO][0m Directory( D:\GoCode\src\kratos-demo/internal/server/http )
2020/03/18 16:34:09 gowatch.go:79: [32m[INFO][0m Directory( D:\GoCode\src\kratos-demo/internal/service )
2020/03/18 16:34:09 gowatch.go:79: [32m[INFO][0m Directory( D:\GoCode\src\kratos-demo/test )
2020/03/18 16:34:09 gowatch.go:113: [32m[INFO][0m Start building...
2020/03/18 16:34:09 gowatch.go:136: [32m[INFO][0m Build Args: go build -o ./cmd ./cmd/main.go
2020/03/18 16:34:09 gowatch.go:144: [32m[INFO][0m Build was successful
2020/03/18 16:34:09 gowatch.go:174: [32m[INFO][0m Restarting ./cmd ...
2020/03/18 16:34:09 gowatch.go:184: [32m[INFO][0m Run ./cmd -conf="D:\GoCode\src\kratos-demo\configs"
2020/03/18 16:34:09 gowatch.go:187: [32m[INFO][0m ./cmd is running...
运行结果:http服务未启动
The project I'm working on has many branches that at some point are going to be merged to master, and whenever I switch branches with the application running it starts building for each modified file.
Ex.: if I change to a branch that has 100 files different from master, the application will build 100 times.
It would be nice if the application could wait, like, 1 second for files to change to build.
目前:在build时, GOGC强制设置为false。
预期:可以通过配置文件将GOGC设置为打开,因为有的时候go build不开GOGC特别费内存
Correct README to English!
This tool works nicely!
But there is a lot of noise in the output:
2021/11/29 08:45:26 gowatch.go:113: [INFO] Start building...
2021/11/29 08:45:26 gowatch.go:150: [INFO] Build Args: go build -o ./00
2021/11/29 08:45:26 gowatch.go:158: [INFO] Build was successful
2021/11/29 08:45:26 gowatch.go:193: [DEBUG] main pid: 6059
2021/11/29 08:45:26 gowatch.go:194: [DEBUG] pids: []
2021/11/29 08:45:26 gowatch.go:205: [DEBUG] killing MAIN process pid: 6059
❯ gowatch -v
1.5
Is there a config setting to disable the printing of DEBUG and INFO lines?
I find they take too much focus from the output from my actual program. (ERROR lines are still useful.)
$ gowatch
gowatch.go:77: [INFO] Initializing watcher...
gowatch.go:79: [INFO] Directory( /Users/xxx )
gowatch.go:79: [INFO] Directory( /Users/xxx )
gowatch.go:82: [ERROR] Fail to watch directory[ too many open files ]
在 配置里排除 vendor 页也是这样的
看起来有点干,还需要什么信息吗?
我使用Watch功能只想知道代码能否编译通过,因为运行的条件比较复杂,不想自动运行。
Even though go.mod
specifies 1.14: https://github.com/silenceper/gowatch/blob/master/go.mod#L3
This breaks 1.14 builds: https://github.com/silenceper/gowatch/pull/34/files#diff-2873f79a86c0d8b3335cd7731b0ecf7dd4301eb19a82ef7a1cba7589b5252261R98
The correct module for 1.14 is ioutil
: https://pkg.go.dev/io/ioutil#WriteFile
The resulting error is:
# github.com/silenceper/gowatch
--
| src/github.com/silenceper/gowatch/main.go:98:8: undefined: os.WriteFile
如果想要在自动编译时同时执行其他命令,比如文档生成,好像是不行的,比如下面的:
swag init && go build -o app .
If i add a replace directive to the go mod, why does it not recompile?
It'd make sense to have a flag for this, or to automatically do that, instead of having to have a whole config file just for specifying the go.mod file... and i don't even know if putting the file into that config works... haven't tried it, not gonna.
Just a wee bit annoying.
That being said, thanks for the tool!
I have modified the file,but nothing changed.I dont know what is the problem, Could you tell how to deal with it
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.