Skip to content

dragononly/air

 
 

Repository files navigation

Air Go Codacy Badge Go Report Card codecov

☁️ Live reload for Go apps

air

Motivation

When I get started with developing websites in Go and gin framework, it's a pity that gin lacks live-reloading function. In fact, I tried fresh and it seems not much flexible, so I intended to rewrite it in a better way. Finally, Air's born. In addition, great thanks to pilu, no fresh, no air :)

Air is yet another live-reloading command line utility for Go applications in development. Just air in your project root directory, leave it alone, and focus on your code.

NOTE: This tool has nothing to do with hot-deploy for production.

Features

  • Colorful log output
  • Customize build or binary command
  • Support excluding subdirectories
  • Allow watching new directories after Air started
  • Better building process

Installation

Go

The classic way to install

go get -u github.com/cosmtrek/air

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

P.S. Great thanks mattn's PR for supporting Windows platform.

Docker way

Please pull this docker image cosmtrek/air.

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

For example, one of my project 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

Usage

For less typing, you could add alias air='~/.air' to your .bashrc or .zshrc.

First enter into your project

cd /path/to/your_project

The simplest usage is run

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

While I prefer the second way

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

# 2. paste `air_example.toml` into this file, and **modify it** to satisfy your needs.

# 3. run air with your config. If file name is `.air.toml`, just run `air`.
air

See the complete air_example.toml

Debug

air -d prints all logs.

Development

Please note that it requires Go 1.13+ since I use go mod to manage dependencies.

# 1. fork this project

# 2. clone it
mkdir -p $GOPATH/src/github.com/cosmtrek
cd $GOPATH/src/github.com/cosmtrek
git clone git@github.com:<YOUR USERNAME>/air.git

# 3. install dependencies
cd air
make ci

# 4. explore it and happy hacking!
make install

BTW: Pull requests are welcome~

Sponsor

Buy Me A Coffee

Huge thanks to the following supporters. I've always been remembering your kindness.

  • Peter Aba
  • Apostolis Anastasiou
  • keita koga

License

GNU General Public License v3.0

About

☁️ Live reload for Go apps

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 73.4%
  • Shell 23.2%
  • Makefile 2.9%
  • Dockerfile 0.5%