[Awesome Go] Use air to hot live reload for Go apps
air
When I get started with developing websites in Go and Iris or Gin framework, it’s a pity that gin lacks live-reloading.
Air is yet another live-reloading command line utility for Go applications in development. Just air in your project root directory, leave it alone, and focus on your code.
Features
-
Colorful log output
-
Customize build or binary command
-
Support excluding subdirectories
-
Allow watching new directories after Air started
-
Better building process
Installation
The classic way to install
Remember to repalce col-air-example
with your prefer folder.
1 | cd col-air-example |
Configuration
- create a new file
1 | touch .air.toml |
- paste
air_example.toml
into this file, and modify it to satisfy your needs.
See the complete air_example.toml - https://github.com/cosmtrek/air/blob/master/air_example.toml
Run
Run air with your config. If file name is .air.toml
, just run air
.
1 | ~/go/bin/air |
Debug
air -d
prints all logs.
Docker
Please pull this docker image cosmtrek/air.
1 | docker run -it --rm \ |
For example, one of my project runs in docker:
1 | docker run -it --rm \ |
References
[1] cosmtrek/air: ☁️ Live reload for Go apps - https://github.com/cosmtrek/air
[3] cosmtrek/air - Docker Hub - https://hub.docker.com/r/cosmtrek/air
[4] air · pkg.go.dev - https://pkg.go.dev/github.com/cosmtrek/air