README ¶
autoreload
This tool provides the functionality to automatically reload a go application upon source code changes.
About
There are two parts to getting autoreload to work:
-
autoreload (inside docker or your code, for example)
autoreload
works with your code. It's responsible for rebuilding your binary whenever it receives data (what's in the data is irrelevant, it just needs to be something) through the reset port (default:12345
). -
watcher (should be run outside docker/your application, on your machine for example)
The
watcher.sh
script watches for.go
file changes in the project directory, telling the server to restart whenever a change is detected. Runs nc/netcat command to send data to the reset port, which informsautoreload
to rebuildIf you're running with Docker: This should be run outside the docker container, because file system events are not properly detected inside the boot2docker VM: https://github.com/boot2docker/boot2docker/issues/688
-
watcher.sh
will continue to watch the file system and contact the reset port in a loop until cancelled. -
autoreload
will continue to listen on the reset port and rebuild the binary whenever contacted in a loop until cancelled.
Requirements
Currently tested on golang 1.4
and golang 1.5
, but presumably works on other versions
- For Macs, fswatch is required to run
watcher.sh
. - For other systems, anything that can watch the file system and send a packet to port 12345 will work.
Required Ports
Port 12345
must be open for watcher.sh
to communicate with autoreload
.
Port 9000
must be open if you're running the godocs server.
If you're running Docker, see here for how to open ports between Docker and host.
How it works
-
Install
autoreload
go get github.com/graciouseloise/autoreload
-
Set up your application autoreload
cd app/your-go-app $GOPATH/bin/autoreload
-
Run the watcher
./watcher.sh
-
Change some of your source code and watch as the binary is reloaded
Get Help
$GOPATH/bin/autoreload --help
usage: autoreload [<flags>]
Autoreload functionality
Flags:
--help Show context-sensitive help (also try --help-long and --help-man).
-d, --godocs Run godocs server
-c, --command=serve Command arguments for running
--build=./binary Target file to build to and run
--file=main.go File name to build against
-r, --reset-port=12345 Port to listen for reset signal
Examples
You can combine any of the below flags
To run with a local godocs server (default: False
)
$GOPATH/bin/autoreload -d
To specify the filename of the binary being built (default: ./binary
)
$GOPATH/bin/autoreload --build=./my-app
To specify the file to build against (default: No filename)
$GOPATH/bin/autoreload --file=main.go
To run with command line arguments for your application (default: None)
$GOPATH/bin/autoreload -c run
To run with custom reset port (default: 12345
)
$GOPATH/bin/autoreload -r 12346
You'll need to run the watcher with a the same port
./watcher.sh 12346
Documentation ¶
There is no documentation for this package.