Hi, I’m @Luo Zhu

This article was first published on luo Zhu’s official website

This article synchronizes in the public account “luo Zhu early teahouse”, reprint please contact the author.

Creation is not easy, form a habit, quality three even!

motivation

When I started developing sites with the Go and GIN frameworks, unfortunately gin didn’t have real-time reloading. In fact, I tried Fresh and it didn’t seem very flexible, so I decided to rewrite it in a better way. Finally, Air was born. In addition, thank you very much Pilu, without Fresh, there would be no Air.

Air is another command line tool for real-time reinstallation in Go application development. Just add AIR to the root of your project, leave it alone and focus on your code.

Note: This tool is not related to hot deployment in production.

features

  • Colorful log output
  • Custom build or binary commands
  • Support for ignoring subdirectories
  • Allows viewing of new directories after Air is started
  • A better build process

The installation

Go

Classic installation:

go get -u github.com/cosmtrek/air
Copy the code

macOS, Linux, Windows

# binary will be $(go env GOPATH)/bin/air
curl -sSfL https://raw.githubusercontent.com/cosmtrek/air/master/install.sh | sh -s -- -b $(go env GOPATH)/bin

# or install it into ./bin/
curl -sSfL https://raw.githubusercontent.com/cosmtrek/air/master/install.sh | sh -s

air -v
Copy the code

Docker

Please pull this Cosmtrek/Air Docker image:

docker run -it --rm \
    -w "<PROJECT>" \
    -e "air_wd=<PROJECT>" \
    -v $(pwd):<PROJECT> \
    -p <PORT>:<APP SERVER PORT> \
    cosmtrek/air
    -c <CONF>
Copy the code

For example, one of my projects runs in Docker.

docker run -it --rm \
    -w "/go/src/github.com/cosmtrek/hub" \
    -v $(pwd):/go/src/github.com/cosmtrek/hub \
    -p 9090:9090 \
    cosmtrek/air
Copy the code

use

To reduce input, you can add alias air=’~/.air’ to your.bashrc or.zshrc. Enter it in your project first

cd /path/to/your_project
Copy the code

The cheapest way is to run

# firstly find `.air.toml` in current directory, if not found, use defaults
air -c .air.toml
Copy the code

I prefer the second way:

# 1. Create a new file
touch .air.toml

# 2. Copy 'air_example.toml' into this file and modify it as you want.

# 3. Run 'air'
air
Copy the code

debugging

Air-d prints all logs.