canthefason / go-watcher Goto Github PK
View Code? Open in Web Editor NEWWatch your .Go files and restart your processes without any configuration hassle
License: MIT License
Watch your .Go files and restart your processes without any configuration hassle
License: MIT License
When I try to run watcher
, I get the error, Could not watch folder no space left on device
. My device has ~75% capacity left on the SSD
Great tool, though there's one big problem. I use other watcher (go-razor's templates watcher) which builds .go templates on change, but seems like 99% of the time go-watcher can't yet get changed templates so it rebuilds with an old version. Maybe there's a quick fix (timeout) for this? Thanks.
Hi, I have a panic when I run go-watcher
go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/alex/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/alex/go"
GORACE=""
GOROOT="/usr/lib/go"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build165720837=/tmp/go-build -gno-record-gcc-switches"
Command
$ watcher
Error
2018/03/11 19:40:05 Could not run the go binary: exec: "-.-785150": executable file not found in $PATH
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x46ef4e]
goroutine 7 [running]:
os.(*Process).signal(0x0, 0x502320, 0x56c0e8, 0x0, 0x0)
/usr/lib/go/src/os/exec_unix.go:56 +0x2e
os.(*Process).Signal(0x0, 0x502320, 0x56c0e8, 0xc42008e100, 0xc420090120)
/usr/lib/go/src/os/exec.go:129 +0x3f
os.(*Process).kill(0x0, 0xc4200900f0, 0x2)
/usr/lib/go/src/os/exec_posix.go:54 +0x43
os.(*Process).Kill(0x0, 0x0, 0x54)
/usr/lib/go/src/os/exec.go:114 +0x2b
github.com/canthefason/go-watcher.(*Runner).kill(0xc42000a160, 0xc4201122c0)
/home/alex/go/src/github.com/canthefason/go-watcher/run.go:66 +0x41
github.com/canthefason/go-watcher.(*Runner).Run(0xc42000a160, 0xc42000a0c0)
/home/alex/go/src/github.com/canthefason/go-watcher/run.go:39 +0x211
created by main.main
/home/alex/go/src/github.com/canthefason/go-watcher/cmd/watcher/main.go:17 +0x110
If you want to reproduce I just listen on a tcp socket. You can ask for anything else.
Nice tool!
I'm looking at the containerized version and I'd like to add a step to do go get (to get the dependencies installed into the file system on the container). A very little local testing suggests this could be achieved by adding go get ./...
just before the exec line in entrypoint.sh.
Happy to do a PR but I thought I'd run the idea past you first. Wdyt?
Getting errors while on go get
:
build github.com/canthefason/go-watcher/cmd/watcher: cannot load gopkg.in/fsnotify.v1: cannot find module providing package gopkg.in/fsnotify.v1
Could this one be related?
On Windows using Docker inotify from the filesystem won't pick up changes. Can you add an option for polling changes?
It would be helpful for readability if there was a flag that would tell watcher to clear the terminal when a re-build was started.
If there is a work around that exists currently, please let me know!
Travis is currently building on versions 1.5 and 1.6 of Go, however runtime.KeepAlive is only present in versions 1.7+ of Go, as referenced here.
This is making most builds fail I think. Error can be seen for the missing field here
# golang.org/x/sys/unix
../../../golang.org/x/sys/unix/ioctl.go:18: undefined: runtime.KeepAlive
../../../golang.org/x/sys/unix/ioctl.go:28: undefined: runtime.KeepAlive
../../../golang.org/x/sys/unix/syscall_linux.go:99: undefined: runtime.KeepAlive
github.com/canthefason/go-watcher/docker-examples/hello
github.com/canthefason/go-watcher/vendor/gopkg.in/fsnotify.v1
The command "eval go get -v -t ./... " failed. Retrying, 2 of 3.
Hi,
I'm using vim to write my .go files and the default behavior of vim is the following:
- write buffer to new file
- delete the original file
- rename the new file
I therefore get a lot of this:
Building project/something...
can't load package: package project/something: no Go files in /home/roland/go/src/project/something
An error occurred while building: exit status 1
My guess is that this has something to do with timers. Your watcher seems to update faster than vim writes/moves the file. Is there any way to modify that?
Hi,
first of all, thanks for implementing a watcher, which is as small and concise, as I want it to be!!
I've found a little bug in my humble opinion, though:
If you start the watcher with keepalive flag and startcmd flag, and the command returns a non zero.
watcher -cmd="false" --keepalive --startcmd
As far as I can see there is no option to build Go binaries with the -race
flag set; the go build
command is hard-coded as:
cmd, err := runCommand("go", "build", "-i", "-o", fileName, pkg)
did I miss something?
Could this option be added? Perhaps it would be good to allow passing arbitrary flags to go build
; maybe after --
?
watcher -c appflag -run example.com/pkg -- -race
Or maybe something like?
watcher -c appflag -run example.com/pkg -buildflags '-race'
I was reading the unit test file you've made, and I found a wrong labelling I guess.
At this line you wrote:
expected true, got false
for the .md file. But I guess it should be ( looking at the IF condition ):
expected false, got true
right?
I get this error
Could not watch folder: too many open files
taras@taras-Z370-HD3P /media/taras/Storage/source/server-panel $ watcher
2018/02/10 17:52:26 build started
Building ....
2018/02/10 17:52:27 build completed
Running ...
2018/02/10 17:52:27 Could not run the go binary: exec: "-.-533426": executable file not found in $PATH
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4718b8]
goroutine 7 [running]:
os.(*Process).signal(0x0, 0x573800, 0x5720e8, 0x0, 0x0)
/usr/local/go/src/os/exec_unix.go:56 +0x38
os.(*Process).Signal(0x0, 0x573800, 0x5720e8, 0x54, 0xc420082180)
/usr/local/go/src/os/exec.go:121 +0x3f
os.(*Process).kill(0x0, 0xc4200840f0, 0x2)
/usr/local/go/src/os/exec_posix.go:53 +0x43
os.(*Process).Kill(0x0, 0x0, 0x54)
/usr/local/go/src/os/exec.go:106 +0x2b
github.com/canthefason/go-watcher.(*Runner).kill(0xc42000a500, 0xc42014e160)
/home/taras/go/src/github.com/canthefason/go-watcher/run.go:66 +0x41
github.com/canthefason/go-watcher.(*Runner).Run(0xc42000a500, 0xc42000a080)
/home/taras/go/src/github.com/canthefason/go-watcher/run.go:39 +0x23c
created by main.main
/home/taras/go/src/github.com/canthefason/go-watcher/cmd/watcher/main.go:17 +0x120
I was testing your Docker right now and I was having a weird issue. Even if I mapped the Volume correctly, I was having this output by watcher
:
can't load package: package .: no buildable Go source files in /go
Then after some trials, I found that the issue was mainly because you're missing the WORKDIR
declaration in the Dockerfile.
For now I fixed it by declaring it on the docker run
command line, although would be nice to have it directly there.
Thanks again and keep up with this awesome project :)
My go app is a http server with go routines.
When I run it the first time it's fine
watcher -c config -p 7777 -run /c/Projects/go/src/gitlab.com/jeremyjohn/http-project -watch gitlab.com/jeremyjohn/http-project
It starts two watcher-http-project process up and the main watch process.
But after changes to a .go file i get this error
2019/08/16 23:05:15 build started
Building C:/Projects/go/src/gitlab.com/jeremyjohn/http-project...
2019/08/16 23:05:16 build completed
Running C:/Projects/go/src/gitlab.com/jeremyjohn/http-project...
2019/08/16 23:05:16 listen tcp :7007: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.
Currently there are only 4 supported file extensions: go
, tmpl
, tpl
and html
though this is problematic, because for example the gotemplate-syntax VSC extension works with .gohtml
extensions by default.
I propose adding a configuration option to be able to freely configure the extensions to watch and fallback to defaults ones when the option is not set.
like go run -tags=enable_trace
It does not work with the following message:
$ watcher
2019/10/24 21:02:15 build started
Building ....
2019/10/24 21:02:17 build completed
Running ...
2019/10/24 21:02:17 process interrupted: signal: killed
Other people from my team who upgraded to Catalina report the same
$ go version
go version go1.12.9 darwin/amd64
It seems that the watcher can no longer be used with the newest version of Go 1.20.1
The problem is that up until now the -i
flag was deprecated and using it gave a warning, but the watcher was successfully building the binary.
From Go 1.20.1 the watcher no longer works, because using the -i
flag returns an error, not a warning:
myservice | flag provided but not defined: -i
myservice | usage: go build [-o output] [build flags] [packages]
myservice | Run 'go help build' for details.
myservice | A build error occurred. Please update your code...
Can you please update the code or would you accept a PR that does that? Thank you!
Does someone know of a alternative similar to the go-watcher which is maintained and supports new Go versions?
I'm trying to use watcher with a REST server. I have src
and public
directories in the application directory. It seems I can't run the watcher
command from the application directory and must instead run it from the src
directory. But this causes an issue with serving static files because my server expects to find those in ./public
, not ../public
. Is there any way I can tell watcher to watch the files in src
and start it from my application directory?
I've seen no new commits in a number of years and as newer go versions are released issues are being encountered here.
With each file change, we are sending SIGKILL command for killing the running process. The problem is, it would leave some open connections behind. For the programs that require graceful shutdowns, it is better to have an optional SIGINT support for go-watcher.
how to watch with more frequency?
the compile time is too much. it takes a long to see the changes (about 5 seconds )
https://github.com/canthefason/go-watcher
watcher -c config -p 7000 -h localhost
I want to see the changes faster
if a remodify a file while a build is already triggered, it gets into an infinite loop. I got into this issue while I am running in a container, maybe it could be related with the processing time.
Hello, first of all, I'm sorry for my English, I had help from Google Translator ... rsrs
I'm trying to use your library on MacOS Mojave. For this I followed exactly as it is in README.md:
go get github.com/canthefason/go-watcher
go install github.com/canthefason/go-watcher/cmd/watcher
commandBut even so it was not possible to run the watcher
command on the terminal.
Could you help me, please?
I was wondering how to use your Docker, if you didn't declare a Volume. Which will be the path that it will watch? Can you add support for Volumes? Would be a nice-to-have feature :)
Best regards,
Julian
Currently, we only have support for Go Version 1.6.3. We need to extend it and add support for other versions, as well.
It seems this is unmaintained but figured I'd raise this anyway.
A reason I usually go build -o app.exe ; ./app.exe
is to keep security software from treating each compilation as a new binary (because it uses a temporary directory). Otherwise, if the application wants access to certain resources such as network sockets, webcams, sound, etc. then you must hit "allow access" for every compilation.
I went to try this app, and it seems it also uses a different output name for every compilation. Resulting in this:
It also doesn't seem to clean up these temporary binaries, which has resulted in my %userprofile%/go/bin directory filling up with executables named watcher-.-(random ID)
.
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.