Home > Article > Backend Development > Detailed explanation of using air to automatically reload code
The following tutorial column from golang will introduce to you how to use air to automatically reload the code. I hope it will be helpful to friends in need!
Air can monitor the project code in real time, automatically recompile and execute after the code changes
(1). You can download Air at https://github.com/cosmtrek/air/releases
, put it into the bin directory under the GO installation directory, and rename it For air.exe
(2), in the windows command window, you can also use curl -fLo air.exe https://git.io/windows_air
command to install Air (to access the external network, enable GO Module and set Detailed explanation of using air to automatically reload code Proxy for acceleration)
After installation, we can use the air -v
command to check in the built-in command line terminal of Detailed explanation of using air to automatically reload codeLand Whether the installation is successful:
Enable Air# through the
air
package mainimport ( "fmt" "net/http")func handlerFunc(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, "<h1>Air自动重载<h1>")}func main(){ http.HandleFunc("/", handlerFunc) http.ListenAndServe(":3030", nil)}</h1> </h1>Access localhost:3030/ in the browser and display Modify the code
package mainimport ( "fmt" "net/http")func handlerFunc(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, "<h1>Air自动重载<h1>")}func main(){ http.HandleFunc("/", handlerFunc) http.ListenAndServe(":3000", nil)}</h1> </h1>Access localhost:3030/ and localhost:3000/ respectively, the effect is as follows:
$ git status
It is not difficult to find that the
tmp directory appears in the project root directory. This directory It is the storage place for Air compiled files. We need to set up the version controller to exclude the tmp
directory. Create a new
file in the root directory, which instructs Git which files and directories to ignore when you commit. After creation, add the tmp
directory to the .gitignore
file:
At this point, we can use the command to view the file status. It can be found that the tmp directory is excluded:
The above is the use of Air automatic reloading in the GO project.
The above is the detailed content of Detailed explanation of using air to automatically reload code. For more information, please follow other related articles on the PHP Chinese website!