Home>Article>Backend Development> Detailed explanation of using air to automatically reload code
The following tutorial column fromgolangwill 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 athttps://github.com/cosmtrek/air/releases
, put it into the bin directory under the GO installation directory, and rename it Forair.exe
(2), in the windows command window, you can also usecurl -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 theair -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, "Access localhost:3030/ in the browser and display Modify the codeAir自动重载
")}func main(){ http.HandleFunc("/", handlerFunc) http.ListenAndServe(":3030", nil)}
package mainimport ( "fmt" "net/http")func handlerFunc(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, "Access localhost:3030/ and localhost:3000/ respectively, the effect is as follows:Air自动重载
")}func main(){ http.HandleFunc("/", handlerFunc) http.ListenAndServe(":3000", nil)}
$ git status
It is not difficult to find that the
tmpdirectory 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 thetmp
directory.Create a new
file in the root directory, which instructs Git which files and directories to ignore when you commit. After creation, add thetmp
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!