Home>Article>Backend Development> Detailed explanation of using air to automatically reload code

Detailed explanation of using air to automatically reload code

藏色散人
藏色散人 forward
2021-03-22 17:19:54 2738browse

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!

Detailed explanation of using air to automatically reload code

Air can monitor the project code in real time, automatically recompile and execute after the code changes

Install Air (windows )

(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_aircommand 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 -vcommand to check in the built-in command line terminal of Detailed explanation of using air to automatically reload codeLand Whether the installation is successful:

Detailed explanation of using air to automatically reload code

Use and test Air

Enable Air# through theair

command

Detailed explanation of using air to automatically reload code

##Run the following code:

package mainimport ( "fmt" "net/http")func handlerFunc(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, "

Air自动重载

")}func main(){ http.HandleFunc("/", handlerFunc) http.ListenAndServe(":3030", nil)}

Access localhost:3030/ in the browser and display

Detailed explanation of using air to automatically reload code

Modify the code

package mainimport ( "fmt" "net/http")func handlerFunc(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, "

Air自动重载

")}func main(){ http.HandleFunc("/", handlerFunc) http.ListenAndServe(":3000", nil)}

Access localhost:3030/ and localhost:3000/ respectively, the effect is as follows:

Detailed explanation of using air to automatically reload code

Detailed explanation of using air to automatically reload code

## Code versionUse the command to check the file status:

$ git status

Detailed explanation of using air to automatically reload codeIt 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 thetmpdirectory.Create a new

.gitignore

file in the root directory, which instructs Git which files and directories to ignore when you commit. After creation, add thetmpdirectory to the.gitignorefile:

Detailed explanation of using air to automatically reload codeAt this point, we can use the command to view the file status. It can be found that the tmp directory is excluded:

Detailed explanation of using air to automatically reload codeThe 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!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete