我知道AppEngine会这样做,但我不是为它编码.
我尝试使用Guard
Ruby世界,监听.go
文件的变化,并执行以下命令:
killall foo
go build -race
./foo &
Run Code Online (Sandbox Code Playgroud)
但它永远不会发送foo
到后台,它只是无限期地挂起.
你们是怎么解决这个问题的?解决方案也必须是跨平台的(GNU/Linux和Mac).
swy*_*wyx 20
有一个 go 版本的 nodemon:https ://github.com/mitranim/gow
go install github.com/mitranim/gow@latest
Run Code Online (Sandbox Code Playgroud)
用法
# Start and restart on change
gow run .
# Pass args to the program
gow run . arg0 arg1 ...
# Run subdirectory
gow run ./subdir
# Vet and re-vet on change; verbose mode is recommended
gow -v vet
# Clear terminal on restart
gow -c run .
# Specify file extension to watch
gow -e=go,mod,html run .
# Help
gow -h
Run Code Online (Sandbox Code Playgroud)
小智 19
一位朋友写了一个简单的Compile Daemon for go,就像我自己的小网/ http项目的魅力一样.
您可以在此处找到存储库:https://github.com/githubnemo/CompileDaemon
Bij*_*jan 11
您还可以通过Codegangsta试用Gin.这是火和忘记.
https://github.com/codegangsta/gin
编辑:我现在更喜欢CompileDaemon.杜松子酒有时不接受请求
另一种选择,如果您的机器上安装了 nodejs
使用 -g安装nodemonnpm i -g nodemon
转到您的代码目录并运行:
nodemon --watch './**/*.go' --signal SIGTERM --exec 'go' run cmd/MyProgram/main.go
Run Code Online (Sandbox Code Playgroud)
这将在每次任何.go
文件更改时发送 SIGTERM并将运行go run cmd/Myprogram/main.go
完全跨平台。
我使用了一个名为entr的工具
安装brew install entr
(mac)
或sudo apt-get install entr
(linux)
要重新编译并运行.go
文件更改,请运行以下命令...
ls **/*.go | entr go run main.go
Run Code Online (Sandbox Code Playgroud)
小智 6
最好的选择是在你的机器上安装nodejs并使用nodemon
包
使用-g安装nodemonsudo npm install -g nodemon
还使用 sudo 以避免任何写入权限
现在转到您的程序目录并运行:
nodemon --watch './**/*.go' --signal SIGTERM --exec 'go' run path-to-the-main-file-of-go-program-with-extension
Run Code Online (Sandbox Code Playgroud)
每次任何.go
文件更改时都会发送 SIGTERM 并将运行go run main-go-file-of-program-with-extension
完全跨平台。这适用于任何编程语言,只需将命令更改为
nodemon --watch './**/*.extension-of-programming-file-without-preceeding-dot' --signal SIGTERM --exec 'go' run path-to-the-main-file-of-program-with-extension
Run Code Online (Sandbox Code Playgroud)
我最近发现了一种反射工具。它的速度很快,而且就像一种魅力。它与nodemon(来自nodejs的世界)和guard(来自ruby的世界)非常相似。
大多数情况下,我使用它的方式类似于以下内容:
reflex -d none -s -R vendor. -r \.go$ -- go run cmd/server/main.go
但是将其选项保存在.reflex之类的文件中,其内容可能像这样更方便:
-d none -s -R vendor. -r \.go$
所以你就这样运行它
reflex $(cat .reflex) -- go run cmd/server/main.go
您可以对“热重载”测试执行相同的操作:
reflex $(cat .reflex) -- go test ./... -v
还有一个配置选项,您可以在其中指定同时运行的许多命令,但我并不真正使用它。