Lightweight automatic reloading of Go processes.
Switch branches/tags
Nothing to show
Clone or download
Carpetsmoker Merge pull request #3 from msokk/fix-darwin
Workaround fix for reloading on macOS
Latest commit 9285b66 Sep 1, 2018
Permalink
Failed to load latest commit information.
bin Inject log function Nov 22, 2017
.gitignore Inject log function Nov 22, 2017
.travis.yml Inject log function Nov 22, 2017
Gopkg.lock Inject log function Nov 22, 2017
Gopkg.toml Inject log function Nov 22, 2017
LICENSE Genesis Aug 23, 2017
README.md Use gddo Aug 24, 2018
reload.go Fix reloading on macOS Sep 1, 2018
reload_test.go Inject log function Nov 22, 2017

README.md

GoDoc Build Status codecov

Lightweight automatic reloading of Go processes.

After initialisation with reload.Do() any changes to the binary (and only the binary) will restart the process. For example:

func main() {
    go func() {
        err := reload.Do(log.Printf)
        if err != nil {
            // Only returns initialisation/startup errors.
            panic(err)
        }
    }()

    // Replace with actual code...
    time.Sleep(666 * time.Second)
}

Now use go install or go build to restart the process.

This is an alternative to the "restart binary after any *.go file changed"-strategy that some other projects – such as gin or go-watcher – take. The advantage of reload's approach is that you have a more control over when the process restarts, and it only watches a single directory for changes which has some performance benefits, especially when used over NFS or Docker with a large number of files.

It also means you won't start a whole bunch of builds if you update 20 files in a quick succession. On a desktop this probably isn't a huge deal, but on a laptop it'll save some battery power.

Caveat: the old process will continue running happily if go install has a compile error, so if you missed any compile errors due to switching the window too soon you may get confused.