Detailed explanation of using air to automatically reload code

藏色散人
Release: 2021-03-22 18:51:16
forward
2822 people have browsed it

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!

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 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:

Detailed explanation of using air to automatically reload code

Use and test Air

Enable Air# through the air

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, "<h1>Air自动重载<h1>")}func main(){
    http.HandleFunc("/", handlerFunc)
    http.ListenAndServe(":3030", nil)}</h1>
</h1>
Copy after login
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, "<h1>Air自动重载<h1>")}func main(){
    http.HandleFunc("/", handlerFunc)
    http.ListenAndServe(":3000", nil)}</h1>
</h1>
Copy after login
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 version Use the command to check the file status:

$ git status
Copy after login

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 the tmp directory. Create a new

.gitignore

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:

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!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template