I have API code written that exists in my $GOPATH but the main file is elsewhere on the system. I'm trying to get my main file to exit and start and again whenever certain files are saved. The closest I've gotten is by using a combination of find
and entr
:
find $GOPATH/github.com/example/example -path $GOPATH/example/example/vendor -prune -o -name '*.go' -print | entr -r go run /vagrant/script/api/main.go
But for some reason entr
fails to shut the service down before starting it again resulting in the error message:
ListenAndServe: listen tcp 127.0.0.1:1456: bind: address already in use
Open to any solution that allows live reloading of the go server, but the less configuration/setup required the better as I'd like to reuse the solution in multiple projects.
Not sure this is an issue, but I should also note that I'm using vagrant-fsnotify to touch changed files in my Vagrant guest machine when saved on the host machine.