Live reload is a handy feature that enables developers to view updates to their code instantly, streamlining the workflow by removing the need to manually stop and restart the server after every change. Honestly, I think Golang is a compiled language so we can't reload directly in Golang, but I saw many developers on Reddit saying it's useful and I tried it. That’s why I am writing this to share something I just recently learned.
What is air?
Air is a live reload tool created for Go developers, allowing your application to refresh automatically whenever changes are made to the codebase. This eliminates the need to manually stop and restart the server after each update, making the development process more efficient and seamless.
Although Go’s speed and simplicity make it a powerful language, the conventional development workflow often requires manually restarting the application after making code changes. This process can be time-consuming and significantly affect the overall development experience.
With some advantages, I can say:
Automatic Reloading: Air monitors your Go files and reloads the server instantly whenever changes are saved.
Streamlined Workflow: Forget the hassle of manually stopping and restarting the server—Air reflects your updates in real time.
Enhanced Developer Experience: Focus on coding and accelerate your progress without the distraction of restarting your application.
Install air
To get started, you’ll need to install Air using Go’s package manager. Open your terminal and execute the following command:
go install github.com/cosmtrek/air@latest
If you’re using Homebrew on macOS, you can do this:
brew install cosmtrek/tap/air
After installation, you can verify it's working by entering the following command:
air -v
This will display the installed version of Air.
Set up and Run air
Go to the root directory of your project.
Generate a default
.air.toml
configuration file by running:air init
This command will create a
.air.toml
file, which includes customizable settings such as directories to monitor, file extensions to watch, and build commands. The default configuration should work well, but you can explore additional options for customization hereWith everything configured, you’re ready to use Air in your Go project. Execute the following command from your project directory:
air
Air will automatically detect changes to your Go files, refresh the server instantly, and display any errors in the console.
You can refer to this repo to explore my config for Golang project
Conclusion
That is it for this article published on Christmas. I hope you found this article useful, if you need any help please let me know by directly inbox.
Let's connect on Twitter and LinkedIn.
👋 Thanks for reading, Merry Christmas and see yaaaaaaaa