Go Web 程序 Live reload 工具

栏目: IT技术 · 发布时间: 4年前

Air

:cloud: Live reload for Go apps

Go Web 程序 Live reload 工具

:fire: :fire: :fire: JOB HIRING

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

curl -fLo air https://git.io/darwin_air

Linux

curl -fLo air https://git.io/linux_air

Windows

curl -fLo air.exe https://git.io/windows_air

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.conf` in current directory, if not found, use defaults
air -c .air.conf

While I prefer the second way

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

# 2. paste `air.conf.example` into this file, and **modify it** to satisfy your needs.

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

See the complete air_example.conf

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

Go Web 程序 Live reload 工具

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

  • Peter Aba

License

GNU General Public License v3.0


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

用户至上:用户研究方法与实践(原书第2版)

用户至上:用户研究方法与实践(原书第2版)

凯茜·巴克斯特 / 王兰、杨雪、苏寅 / 机械工业出版社 / 2017-5-1 / 99

《UI/UE系列丛书 用户至上:用户研究方法与实践(原书第2版)》是用户研究方法指南,谷歌用户体验研究员十几年工作经验结晶,从理论到实战,包含完整的实操案例,是设计以人为中心产品的实用手册。 《UI/UE系列丛书 用户至上:用户研究方法与实践(原书第2版)》包含五个部分共15章。入门篇包括第1~5章:介绍用户体验入门,如何理解目标用户,道德与法律问题,如何搭建研究设施,如何选择用户体验研究方......一起来看看 《用户至上:用户研究方法与实践(原书第2版)》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

MD5 加密
MD5 加密

MD5 加密工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试