Note: deprecated in favor of https://github.com/Mitranim/gow since Go 1.11.
Minimal CLI tool for Go development. Can:
- run an entire Go package with a single command, without
go build
- optionally watch and rerun on file changes
Works on MacOS, should work on Linux. Pull requests for Windows are welcome.
- one command to build and run
- easy to remember
- can watch and rerun
The Go team has rejected multiple proposals to add directory support to go run
: [1][2]. One has finally been accepted: [3], but is not part of a stable Go release at the time of writing.
Existing runners, like realize
, tend to:
- have an earth-shattering amount of bells and whistles
- have verbose logging you can't disable
- have unnecessary delays in the file watcher
- use CPU constantly
- require config files
- put garbage in the working directory
- mess with file paths in error reports
- have thousands of lines of code, so you can't fix them yourself
gorun
doesn't.
go get -u github.com/Mitranim/gorun
This will automatically compile the executable. Make sure $GOPATH/bin
is in your $PATH
so the shell can discover it. For example, my ~/.profile
contains this:
export GOPATH=~/go
export PATH=$PATH:$GOPATH/bin
# Run current directory
gorun .
# Run subdirectory
gorun ./src/go
# Specify process name
gorun -n=my-app .
# Watch and rerun
gorun -w .
# Any additional arguments are passed to the program
gorun . arg0 arg1 arg2 ...
# Usage info
gorun -h
Now ignores non-.go
files when watching, regardless of the watch pattern.
Now uses go install
when possible, falling back on go build
.
When gorun
uses go build
and is stopped with ^C
or by closing a terminal tab, it immediately deletes its temporary directory with the binary.
After updating gorun
, delete any leftover directories:
find $TMPDIR -name "gorun-*" -delete
Verbose log now includes build duration.
Consider stopping the child process with SIGINT
to allow cleanup; don't forget a timeout.
For general purpose file watching, consider these excellent tools:
Differences:
gorun
builds and runs a Go directory, which can be fiddly and awkward otherwise.- Most general-purpose watchers don't support killing and restarting the child process;
watchexec
is one of the few exceptions. - For Go, remembering how to invoke
gorun
is much easier.
https://en.wikipedia.org/wiki/WTFPL
I'm receptive to suggestions. If this tool almost satisfies you but needs changes, open an issue or chat me up. Contacts: https://mitranim.com/#contacts