LinuxCommandLibrary

goreload

Reloads Go applications during development

TLDR

Watch a binary file (defaults to .goreload)

$ goreload [[-b|--bin]] [path/to/binary] [path/to/file.go]
copy

Set a custom log prefix (defaults to goreload)
$ goreload --logPrefix [prefix] [path/to/file.go]
copy

Reload whenever any file changes
$ goreload --all
copy

SYNOPSIS

goreload [options] [command [args...]]

PARAMETERS

-binary, -b string
    Binary name to execute (default: go)

-cmd, -c string
    Subcommand to run (default: run)

-delay, -d duration
    Delay before restarting (default: 500ms)

-dir, -D string
    Working directory to watch (default: current)

-exclude, -e string
    Comma-separated patterns to exclude from watching

-include, -i string
    Comma-separated extensions to include (default: .go)

-v
    Enable verbose logging

-h, --help
    Show help

DESCRIPTION

Goreload is a development tool for Go programmers that automatically detects changes in source files and restarts the application binary. It monitors directories recursively for .go files (and optionally others), compiles and runs the updated code seamlessly, eliminating manual restarts during development.

Ideal for web servers, CLI tools, or any executable Go program, goreload forks the process, watches for file system events, kills the old process on changes, and spawns a new one. This boosts productivity, especially in iterative coding sessions.

Typically installed via go install from a GitHub repository like github.com/fvbiasini/goreload or similar forks. It supports custom commands, exclude patterns, and delays to handle rapid successive changes. Note that stateful applications may lose data on restarts unless persisted externally.

While powerful for dev workflows, it's not intended for production due to overhead and potential instability during reloads.

CAVEATS

Development-only tool; restarts lose in-memory state. High CPU on watched dirs with many files. Fork-specific behaviors vary; test thoroughly.

INSTALLATION

go install github.com/fvbiasini/goreload@latest
Or clone and go install from other repos.

EXAMPLES

goreload main.go
goreload -e 'vendor/*,*.pb.go' go run .

WITHOUT ARGS

Defaults to goreload go run . watching current dir.

HISTORY

Originated around 2013 as early live-reload solution for Go (e.g., github.com/astaxie/goreload). Multiple forks evolved; largely superseded by Air (cosmtrek/air) since 2019 for richer features like .air.toml configs.

SEE ALSO

air(1), reflex(1), watchexec(1), go(1), entr(1)

Copied to clipboard