Air — Live Reload for Go Applications
Air provides live reload for Go development. It watches your source files, automatically rebuilds on changes, and restarts the binary — giving you a hot-reload experience similar to nodemon for Node.js or Flask debug mode for Python.
Installation agent prête
Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.
npx -y tokrepo@latest install 1075acd7-373d-11f1-9bc6-00163e2b0d79 --target codexÀ exécuter après confirmation du plan en dry-run.
What it is
Air is a live-reload utility for Go applications. It monitors your project directory with fsnotify, and every time a .go file changes it rebuilds the project and restarts the binary automatically. This brings the instant feedback loop common in JavaScript (nodemon) and Python (Flask debug mode) to Go development.
Air is aimed at Go backend developers who want faster iteration cycles during local development. It supports custom build commands, file exclusion patterns, colored log output, and proxy mode for web frameworks.
How it saves time or tokens
Without Air, every code change requires manually stopping the server, running go build, and restarting. Air collapses this into a single save action. It handles debouncing (multiple rapid saves trigger only one rebuild), displays build errors inline without crashing, and forwards signals like SIGINT so graceful shutdown works correctly.
For teams using AI coding assistants that write and edit Go files, Air keeps the running server always in sync with the latest code without manual intervention.
How to use
- Install Air:
go install github.com/air-verse/air@latest
- Initialize the config file in your project root:
air init
This creates .air.toml with sensible defaults.
- Start watching:
air
Air now rebuilds and restarts on every file change.
Example
Minimal .air.toml configuration:
root = '.'
tmp_dir = 'tmp'
[build]
cmd = 'go build -o ./tmp/main .'
bin = './tmp/main'
watch = ['.']
exclude_dir = ['assets', 'tmp', 'vendor', 'node_modules']
include_ext = ['go', 'tpl', 'tmpl', 'html']
delay = 1000 # ms debounce
[log]
color = true
Or run without any config file:
air --build.cmd 'go build -o ./tmp/main .' --build.bin './tmp/main'
Related on TokRepo
- Automation Tools -- Developer workflow automation and productivity tools
- DevOps Tools -- Build, deploy, and infrastructure tooling
Common pitfalls
- Air watches the current directory by default. If your main package is in a subdirectory, set
rootin.air.tomlor run Air from that directory. - On macOS, fsnotify may hit the default file descriptor limit with large projects. Increase it with
ulimit -n 10240if Air misses changes. - Air does not run tests automatically. Pair it with a separate test watcher if you want test-on-save behavior.
Questions fréquentes
Air serves the same purpose as nodemon but for Go. It watches source files, rebuilds on change, and restarts the binary. The key difference is Air runs a full Go compilation step, while nodemon simply restarts the Node.js process.
Yes. Air runs whatever build command you configure, typically 'go build', which respects your go.mod and module dependencies. No special configuration is needed for Go modules.
Yes. Set the include_ext option in .air.toml to list additional file extensions. For example, adding 'html' and 'tmpl' triggers a rebuild when template files change.
Air includes a proxy mode that can forward requests to your application. This is useful for web frameworks where you want Air to manage both the rebuild cycle and request proxying during development.
Use the exclude_dir setting in .air.toml. Common exclusions include vendor, node_modules, tmp, and assets directories to avoid unnecessary rebuilds.
Sources citées (3)
- Air GitHub Repository— Air provides live reload for Go development with fsnotify-based file watching
- Go Documentation— Go install command for installing Go binaries from module sources
- fsnotify GitHub— fsnotify provides cross-platform filesystem notifications for Go
En lien sur TokRepo
Fil de discussion
Actifs similaires
Beego — Full-Featured Go Web Framework with MVC and ORM
Beego is a batteries-included web framework for Go that ships with an MVC architecture, built-in ORM, session handling, caching, and a live-reload dev server.
GoConvey — Go Testing with Browser UI
A BDD-style testing framework for Go that includes a live-reloading browser interface. Write expressive specs with nested Convey blocks and watch results update in real time.
lnav — The Logfile Navigator with SQL and Live Tailing
lnav is an advanced log file viewer that understands dozens of log formats, provides SQL queries against log records, live-tails rotating files, and timestamps-merges multiple logs into one view.
entr — Run Arbitrary Commands When Files Change
entr is a tiny, dependency-free event notify-based tool for running commands when any file in a list changes, perfect for live-reload workflows with tests, linters, and builds.