Code Monkey home page Code Monkey logo

air's Introduction

☁️ Air - Live reload for Go apps

Go Codacy Badge Go Report Card codecov

air

English | 简体中文 | 繁體中文

Motivation

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

Air is yet another live-reloading command line utility for developing Go applications. Run 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 any command
  • Support excluding subdirectories
  • Allow watching new directories after Air started
  • Better building process

Overwrite specify configuration from arguments

Support air config fields as arguments:

If you want to config build command and run command, you can use like the following command without the config file:

air --build.cmd "go build -o bin/api cmd/run.go" --build.bin "./bin/api"

Use a comma to separate items for arguments that take a list as input:

air --build.cmd "go build -o bin/api cmd/run.go" --build.bin "./bin/api" --build.exclude_dir "templates,build"

Installation

Via go install (Recommended)

With go 1.22 or higher:

go install github.com/cosmtrek/air@latest

Via install.sh

# 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
# binary will be /usr/local/bin/air
curl -sSfL https://goblin.run/github.com/cosmtrek/air | sh

# to put to a custom path
curl -sSfL https://goblin.run/github.com/cosmtrek/air | PREFIX=/tmp sh

Docker/Podman

Please pull this docker image cosmtrek/air.

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

Docker/Podman .${SHELL}rc

if you want to use air continuously like a normal app, you can create a function in your ${SHELL}rc (bash,zsh,etc...)

air() {
  podman/docker run -it --rm \
    -w "$PWD" -v "$PWD":"$PWD" \
    -p "$AIR_PORT":"$AIR_PORT" \
    docker.io/cosmtrek/air "$@"
}

<PROJECT> is your project path in container, eg: /go/example if you want to enter the container, Please add --entrypoint=bash.

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

Another example:

cd /go/src/github.com/cosmtrek/hub
AIR_PORT=8080 air -c "config.toml"

this will replace $PWD with the current directory, $AIR_PORT is the port where to publish and $@ is to accept arguments of the application itself for example -c

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

You can initialize the .air.toml configuration file to the current directory with the default settings running the following command.

air init

After this, you can just run the air command without additional arguments and it will use the .air.toml file for configuration.

air

For modifying the configuration refer to the air_example.toml file.

Runtime arguments

You can pass arguments for running the built binary by adding them after the air command.

# Will run ./tmp/main bench
air bench

# Will run ./tmp/main server --port 8080
air server --port 8080

You can separate the arguments passed for the air command and the built binary with -- argument.

# Will run ./tmp/main -h
air -- -h

# Will run air with custom config and pass -h argument to the built binary
air -c .air.toml -- -h

Docker-compose

services:
  my-project-with-air:
    image: cosmtrek/air
    # working_dir value has to be the same of mapped volume
    working_dir: /project-package
    ports:
      - <any>:<any>
    environment:
      - ENV_A=${ENV_A}
      - ENV_B=${ENV_B}
      - ENV_C=${ENV_C}
    volumes:
      - ./project-relative-path/:/project-package/

Debug

air -d prints all logs.

Installation and Usage for Docker users who don't want to use air image

Dockerfile

# Choose whatever you want, version >= 1.16
FROM golang:1.22-alpine

WORKDIR /app

RUN go install github.com/cosmtrek/air@latest

COPY go.mod go.sum ./
RUN go mod download

CMD ["air", "-c", ".air.toml"]

docker-compose.yaml

version: "3.8"
services:
  web:
    build:
      context: .
      # Correct the path to your Dockerfile
      dockerfile: Dockerfile
    ports:
      - 8080:3000
    # Important to bind/mount your codebase dir to /app dir for live reload
    volumes:
      - ./:/app

Q&A

"command not found: air" or "No such file or directory"

export GOPATH=$HOME/xxxxx
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
export PATH=$PATH:$(go env GOPATH)/bin <---- Confirm this line in you profile!!!

Error under wsl when ' is included in the bin

Should use \ to escape the `' in the bin. related issue: #305

Question: how to do hot compile only and do not run anything?

#365

[build]
  cmd = "/usr/bin/true"

Development

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

# Fork this project

# Clone it
mkdir -p $GOPATH/src/github.com/cosmtrek
cd $GOPATH/src/github.com/cosmtrek
git clone [email protected]:<YOUR USERNAME>/air.git

# Install dependencies
cd air
make ci

# Explore it and happy hacking!
make install

Pull requests are welcome.

Release

# Checkout to master
git checkout master

# Add the version that needs to be released
git tag v1.xx.x

# Push to remote
git push origin v1.xx.x

# The CI will process and release a new version. Wait about 5 min, and you can fetch the latest version

Star History

Star History Chart

Sponsor

Buy Me A Coffee

Give huge thanks to lots of supporters. I've always been remembering your kindness.

License

GNU General Public License v3.0

air's People

Contributors

178inaba avatar alexandear avatar amikai avatar anthodev avatar appleboy avatar bbrks avatar borosr avatar chihiros avatar cinaglia avatar cosmtrek avatar cuishuang avatar devdorrejo avatar goenning avatar hecorr avatar kenilt avatar lime008 avatar makiuchi-d avatar mattn avatar mikutas avatar silverwind avatar suzaku avatar svanharmelen avatar the avatar troutowicz avatar tusharsadhwani avatar vishal-wadhwa avatar xiantang avatar zachgrayio avatar zekker6 avatar zhengcan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

air's Issues

Can not print console log properly

System : MacOS 10.14.2
Air version: v1.10


I try to print in many ways, like this:
image

Start in normal:
image
It can print all of log.

Use air to start:
image

The log seems to be printed randomly.

Different log level with different colors

It would be nice to inject diff log levels for runner, builder (and others loggers) with diff colors. It would help to differ common 'INFO' messages from runner from, for example, 'WARNING', that can occur by this #42 case with tmp as '.' (pretty dangerous)

Include dir

Would it be possible to add include_dir which would be used instead of exclude_dir. We have a monolithic repository and it would be easiest to have it watch the root and only include directories the project needs. Thanks!

how to use two cmd ?

windows system:
air.conf file like this

[build]
# Just plain old shell command. You could use `make` as well.
cmd = "swag init && go build -o ./tmp/main.exe main.go"
# Binary file yields from `cmd`.
bin = "tmp/main.exe"
# Customize binary.

full_bin = "tmp/main.exe"

but I found the go build -o /tmp/main.exe main.go does not execute!!!
how to soulve this?

Word from the author

First of all, great thanks to everyone's issue, comment, and PR.

I've been in trouble for months in my life. I'll back soon to review PR and fix bugs. Thanks for your patience and work.

Windows path compatibility issue

First of all, thanks for the great work!

I'm using Windows 10 Enterprise Edition 1607 LTSB, and my .air.conf file is like:

root = "."
tmp_dir = "tmp"

[build]
cmd = "go build -o ./tmp/main.exe ."
bin = "tmp/main.exe"
full_bin = "tmp\main.exe"

It seems air is using cmd to spawn go processes, by default it will generate tmp is not recognized as an internal or external command error, so I changed the \ in full_bin property to /, others are the same as air_example.conf.

Then every time after I changed something, air reloads the peoject, and the console will output an error:

failed to remove C:\path\to\project\tmp\main.exe, error: remove C:\path\to\project\C:\path\
to\project\tmp\main.exe: The filename, directory name, or volume label syntax is incorrect.

It is removing C:\path\to\project\C:\path\to\project\tmp\main.exe while the correct file path is C:\path\to\project\tmp\main.exe. My condition is a little different from issue#2, I don't know why but my windows can remove a file that is in use. And besides the error message, everything just works fine, the program actually gets reloaded and serving correct contents.

make GitHub Short links

make GitHub Short links

curl -i https://git.io -F url="https://raw.githubusercontent.com/xyfll7/test/master/my-test.sh" -F "code=my-test"

result

https://git.io/my-test

use

curl -L https://git.io/my-test | bash

feature-request:About the signal when the killCmd method is executed

🎉Thank you for your air, I like it very much.

I use Gin to write code for the server.
When the server will be shut down,I need to do some processing like closing the database connection.
But because the killCmd method sent the syscall.SIGKILL signal, there is no time to close the database connection.
When my Gin server is started again by air, an error can occur because the database connection is not closed properly and the server cannot be started.
Can I configure the semaphore in config so that I can pass syscall.SIGTERM.
It is better if air can set a timeout for waiting for the kill command to end.

This is just a suggestion, I hope to improve the air this useful tool.

where has windows config sample?

cmd result

!exclude vendor
building...
CMD will not recognize non .exe file for execution, path: go build -o ./cmd/server/server ./cmd/server
running...
CMD will not recognize non .exe file for execution, path: ./cmd/server/server -c ./configs/config.toml -m ./configs/model.conf -swagger ./docs/swagger -menu ./configs/menu.json
'.' is not recognized as an internal or external command,
operable program or batch file.

my config

# Config file for [Air](https://github.com/cosmtrek/air) in TOML format

# Working directory
# . or absolute path, please note that the directories following must be under root
root = "." 
# Optional! If `watch_dir` is empty, use `root`.
watch_dir = ""
tmp_dir = "tmp"

[build]
# Just plain old shell command. You could use `make` as well.
cmd = "go build -o ./cmd/server/server ./cmd/server"
# Binary file yields from `cmd`.
bin = "/cmd/server/server"
# Customize binary.
full_bin = "./cmd/server/server -c ./configs/config.toml -m ./configs/model.conf -swagger ./docs/swagger -menu ./configs/menu.json"
# This log file places in your tmp_dir.
log = "air_errors.log"
# Watch these filename extensions.
include_ext = ["go", "toml"]
# Ignore these filename extensions or directories.
exclude_dir = ["assets", "tmp", "vendor", "data", "docs", "scripts"]
# There's no necessary to trigger build each time file changes if it's too frequency.
delay = 1000 # ms

[log]
# Show log time
time = false

[color]
# Customize each part's color. If no color found, use the raw app log.
main = "magenta"
watcher = "cyan"
build = "yellow"
runner = "green"

[misc]
# Delete tmp directory on exit
clean_on_exit = true

Does not support arguments

My code requires that we follow the execution with a "serve" argument. Is this supported?

I noticed this PR but it seems to be closed:

#12

watch multiple dirs

Hey @cosmtrek ,

Thanks for this awesome tool.
Just wondering that is there any support on watching multiple directories atm? I couldn't find any.
Or is there any plan to add this feature in the future?
Would be really helpful.

Cheers.

can not start air if main fuc in the go file not named with main.go

my entry file is index.go,
when run air, the error output is

can't load package: package main.go: cannot find module providing package main.go
failed to build, error: exit status 1
  • go.mod
module elk-go

go 1.13

require (
	github.com/go-resty/resty/v2 v2.1.0
	github.com/gorilla/schema v1.1.0
	github.com/jinzhu/gorm v1.9.11
	github.com/mailru/easyjson v0.7.0 // indirect
	github.com/olivere/elastic v6.2.25+incompatible
	github.com/oschwald/geoip2-golang v1.3.0
	github.com/oschwald/maxminddb-golang v1.5.0 // indirect
)
  • .air.conf
# Config file for [Air](https://github.com/cosmtrek/air) in TOML format

# Working directory
# . or absolute path, please note that the directories following must be under root.
root = "." 
tmp_dir = "tmp"

[runner]
# Just plain old shell command. You could use `make` as well.
cmd = "MYSQL_PASSWORD=root GO_ENV=development go run index.go"
# Binary file yields from `cmd`.
bin = "tmp/elk-go"
# Customize binary.
# full_bin = "APP_ENV=dev APP_USER=air ./tmp/main"
# Watch these filename extensions.
include_ext = ["go", "tpl", "tmpl", "html"]
# Ignore these filename extensions or directories.
exclude_dir = ["assets", "tmp", "vendor", "frontend/node_modules"]
# Watch these directories if you specified.
include_dir = []
# Exclude files.
exclude_file = []
# It's not necessary to trigger build each time file changes if it's too frequent.
delay = 1000 # ms
# Stop to run old binary when build errors occur.
stop_on_error = true
# This log file places in your tmp_dir.
log = "air_errors.log"

[log]
# Show log time
time = false

[color]
# Customize each part's color. If no color found, use the raw app log.
main = "magenta"
watcher = "cyan"
build = "yellow"
runner = "green"

[misc]
# Delete tmp directory on exit
clean_on_exit = true

Address already in use with docker-compose

Hey, I'm trying to use air within a docker-compose project. The project uses gin as the web server.

Here's my terminal output:

app_1      | [18:52:21.637] [GIN] 2018/02/27 - 18:52:21 | 200 |      40.743µs |      172.18.0.1 |  GET     /status
app_1      | 
app_1      | [18:52:30.303] main.go has changed
app_1      | [18:52:30.303] building...
app_1      | [18:52:30.875] running...
app_1      | [18:52:30.877] [GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
app_1      |  - using env:	export GIN_MODE=release
app_1      |  - using code:	gin.SetMode(gin.ReleaseMode)
app_1      | 
app_1      | 
app_1      | [18:52:30.877] [GIN-debug] GET    /status                   --> main.main.func1 (3 handlers)
app_1      | [GIN-debug] Listening and serving HTTP on :5000
app_1      | 
app_1      | [18:52:30.877] [GIN-debug] [ERROR] listen tcp :5000: bind: address already in use

fsnotify does not work on Docker on Windows

Hello,
Thanks for the great tool but sadly it does not work for shared volume because it's relayed on fsnotify, Please add support for pooling

github.com/radovskyb/watcher works great on Docker on Windows

Windows Docker-desktop and air

Unfortunately, I can't make it work when it's executed from Windows host through Docker-desktop (using docker-compose with a volume). In theory, Docker desktop is correctly configured to share files between Windows and Docker volumes.

I guess the events air is watching are not triggered for some reasons in this setup.

Thank you for the great work here! :)

.env reload

In the configuration file .air.conf.
There is an include_ext parameter.
Add the ability to specify .env files.
Or take a seat on how to set it up.

Warn if tmp dir is the current working directory

In .air.conf, if you set the tmp to ".", your entire current working directory will be wiped. This can be very bad especially if you haven't committed to git in a while. Can we have a warning if it is set to "." or atleast some documentation around that please?

My .air.conf that caused this:

# Working directory
# . or absolute path, please note that the directories following must be under root
root = "." 
# Optional! If `watch_dir` is empty, use `root`.
watch_dir = ""
tmp_dir = "."

[build]
# Just plain old shell command. You could use `make` as well.
cmd = "go build"
# Binary file yields from `cmd`.
bin = "main"

air auto reboot occur error in window10+ go1.14.1+vscode

main.go has changed
building...
failed to remove C:\WS\golang\gzcode\tmp\main.exe, error: remove C:\WS\golang\gzcode\C:\WS\golang\gzcode\tmp\main.exe: The filename, directory name, or volume label syntax is incorrect.
running...

image

Terminal text gets garbled on Windows

Whenever running air on windows the text has issues printing.

λ c:\Users\sonar\.air .

             _
     /\     (_)
    /  \     _   _ __
   / /\ \   | | | '__|
  / ____ \  | | | |
 /_/    \_\ |_| |_|

Live reload for Go apps :)

[19:38:14.574] watching .
[19:38:14.577] watching protos
[19:38:14.579] !exclude tmp
[19:38:14.580] building...
[19:3[81:91:53.83:2155]. 3!2e6x]c l!uedxec ltumdpe
 tmp[
19:38:15.329] !exclude tmp
[19:38:15.341] running...

I get this issue running in git bash as well as cmd.

Config sample for windows

Have found closed issue about config sample for windows

But I am too green in golang so just simple coping does not work.

Can you provide please any working config that will just do go run hello.go for me, beginner or go run main.go (Golang tutorial still haven't told me how to name main file)

sigsegv when using conf

starting with ~/.air on arch linux. go 1.9.2

Live reload for Go apps :)
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x4fc7a2]

goroutine 1 [running]:
github.com/cosmtrek/air/runner.(*Engine).watching.func1(0xc420018180, 0x32, 0x0, 0x0, 0x5e44c0, 0xc42005c5d0, 0x10, 0x5248e0)
	/Users/cosmtrek/Code/go/src/github.com/cosmtrek/air/runner/engine.go:100 +0x32
path/filepath.Walk(0xc420018180, 0x32, 0xc42000f650, 0x6, 0xc420018180)
	/usr/local/opt/go/libexec/src/path/filepath/path.go:401 +0x76
github.com/cosmtrek/air/runner.(*Engine).watching(0xc420072180, 0xc420018180, 0x32, 0xc42000f630, 0x1)
	/Users/cosmtrek/Code/go/src/github.com/cosmtrek/air/runner/engine.go:98 +0x76
github.com/cosmtrek/air/runner.(*Engine).Run(0xc420072180)
	/Users/cosmtrek/Code/go/src/github.com/cosmtrek/air/runner/engine.go:77 +0xf3
main.main()
	/Users/cosmtrek/Code/go/src/github.com/cosmtrek/air/main.go:52 +0x1ea

using this .air.conf

# working directory
root = "." # . or absolute path, please note that the directories following must be under root
watch_dir = "runner" # optional, if no watch_dir, use root
tmp_dir = "tmp"

[build]
exclude_dir = ["node_modules"]
delay = 800 # ms

[color]
main = "magenta"
watcher = "cyan"
build = "yellow"
runner = "green"
app = "white"

or this

# conf for Air in toml format

# working directory
root = "." # . or absolute path, please note that the directories following must be under root
watch_dir = "runner" # optional, if no watch_dir, use root
tmp_dir = "tmp"

[build]
bin = "tmp/server"
cmd = "go build -o ./tmp/server ./cmd/server"
log = "server-errors.log" # this log file places in your tmp_dir
include_ext = ["go", "tpl", "tmpl", "html"]
exclude_dir = ["assets", "tmp", "vendor", "frontend/node_modules"]
delay = 800 # ms

[color]
main = "magenta"
watcher = "cyan"
build = "yellow"
runner = "green"
app = "white"

Exclude specific files

AFAICT, there is currently no way to ignore specific files. This is especially pervasive for 2 reasons:

  1. Generated files
  2. Intermediate files

If either happens to have a specific extension you want watched (and most likely it will be .go), then unless it's always guaranteed to be in a specific directory these will always be watched.

I think instead of just exclude_dir, it should be possible to exclude specific files as well.

Log output doesn't show until close

Unsure this is related to my app or air itself but on Windows when I use log.Print etc for anything the output doesn't show until I cancel out of the running app and then it will dump everything to stdout.

Haven't tested another application yet to see if it's me doing something but thought I would just log it here first and close if it's my fault.

Request feature for pause in build fail

Hi, I would like to request for a feature. My development scene is this.

  • Run "make build" as building command
  • Output artifacts are not cleared before new build

So after build failed, Air runs the the previous success built artifact without noticing. I think a pause would be enough.

Could you please support this feature? thanks :)

Btw, I use air as nginx configuration reloader as well, it's awesome.

Runtime error didnot show

0.env

win 10
go 1.14.1
air v1.12.1

1.create main.go (by gin official example) with a runtime error

package main

import "github.com/gin-gonic/gin"

func main() {
	r := gin.Default()
	r.GET("/ping", func(c *gin.Context) {
		p := (*int)(nil)
		*p = 3 // will throw nil pointer exception
		c.JSON(200, gin.H{
			"message": "pong",
		})
	})
	r.Run()
}

2.run air

$ air

3.detonate

$ curl  http://127.0.0.1:8080/ping

4.result
error message didnot show in air log

Logs can be shown on the terminal, but not be written in the log file.Why?

# Config file for [Air](https://github.com/cosmtrek/air) in TOML format

# Working directory
# . or absolute path, please note that the directories following must be under root.
root = "."
tmp_dir = "tmp"

[build]
# Just plain old shell command. You could use `make` as well.
cmd = "go build -o ./tmp/main ."
# Binary file yields from `cmd`.
bin = "tmp/main"
# Customize binary.
full_bin = "APP_ENV=dev APP_USER=air ./tmp/main"
# Watch these filename extensions.
include_ext = ["go", "tpl", "tmpl", "html"]
# Ignore these filename extensions or directories.
exclude_dir = ["assets", "tmp", "vendor", "frontend/node_modules"]
# Watch these directories if you specified.
include_dir = []
# Exclude files.
exclude_file = []
# This log file places in your tmp_dir.
log = "air.log"
# It's not necessary to trigger build each time file changes if it's too frequent.
delay = 1000 # ms
# Stop running old binary when build errors occur.
stop_on_error = true
# Send Interrupt signal before killing process (windows does not support this feature)
send_interrupt = false
# Delay after sending Interrupt signal
kill_delay = 500 # ms

[log]
# Show log time
time = false

[color]
# Customize each part's color. If no color found, use the raw app log.
main = "magenta"
watcher = "cyan"
build = "yellow"
runner = "green"

[misc]
# Delete tmp directory on exit
clean_on_exit = true

Use default config if not in .air.conf file.

Can we use default config if not specified in .air.conf file?

Example:

air works great without config file, just use air in my cmd and everything works.
But I need to disable time so I create a new file .air.conf with just:

[log]
time = false

in it. Now calling again air doesn't work. It gives an error:

PANIC: runtime error: invalid memory address or nil pointer dereference

I'm on Windows, air installed with go get -u github.com/cosmtrek/air

Add support for override the run command

Hello. First of all congrats on this project.

I need to setup some environment variables when running my application.
The way I am using without air is having the following command in my project Makefile:

server: ## Starts the application server
	APP_ENV=dev go run cmd/server/main.go

This works fine standalone but when running the application from air, I need a way to specify the APP_ENV environment variable.

Remove Ascii art

Is it really required to output this ascii? I would like to see this removed as this just bloats my cli:


U  /"\  u       ___      U |  _"\ u
 \/ _ \/       |_"_|      \| |_) |/
 / ___ \        | |        |  _ <
/_/   \_\     U/| |\u      |_| \_\
 \\    >>  .-,_|___|_,-.   //   \\_
(__)  (__)  \_)-' '-(_/   (__)  (__)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you agree I can make a MR. 😁

build from multiple go files

Using Windows 10 Pro

I have code in two files: main.go and handlers.go.

When I build from the command line, no problem: go build -o ./tmp/main.exe. But when I use that same command within .air.conf, it seems it only builds main.go and ignores handlers.go, because I get the error message:

.\main.go:14:19: undefined: firstFunc
.\main.go:15:22: undefined: secondFunc

the exact line in the config file is cmd = "go build -o ./tmp/main.exe"

How can I run a build within air that includes all the *.go files?

Note -- this also fails: cmd = "go build -o ./tmp/main.exe main.go handlers.go" However even if this worked, it seems like an unsatisfactory answer, eventually I may have a list of 10, 20, 50 files.

Runtime error: invalid memory address or nil pointer dereference

Constantly getting the following error after any file amend:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x4f1aa2]

goroutine 23 [running]:
github.com/cosmtrek/air/runner.(*Engine).watching.func1(0xc4200d8780, 0x4b, 0x0, 0x0, 0x553860, 0xc4200d0360, 0x0, 0x0)
        /Users/cosmtrek/Code/go/src/github.com/cosmtrek/air/runner/engine.go:100 +0x32
path/filepath.walk(0xc420018004, 0x37, 0x5542e0, 0xc4200d3040, 0xc4200de2e0, 0x0, 0x10)
        /usr/local/opt/go/libexec/src/path/filepath/path.go:377 +0x20d
path/filepath.Walk(0xc420018004, 0x37, 0xc4200de2e0, 0x0, 0xc42003cfc8)
        /usr/local/opt/go/libexec/src/path/filepath/path.go:403 +0x106
github.com/cosmtrek/air/runner.(*Engine).watching(0xc4200f0000, 0xc420018004, 0x37, 0x0, 0x0)
        /Users/cosmtrek/Code/go/src/github.com/cosmtrek/air/runner/engine.go:98 +0x74
github.com/cosmtrek/air/runner.(*Engine).watchNewDir.func1(0xc4200f0000, 0xc420018004, 0x37)
        /Users/cosmtrek/Code/go/src/github.com/cosmtrek/air/runner/engine.go:179 +0x43
created by github.com/cosmtrek/air/runner.(*Engine).watchNewDir
        /Users/cosmtrek/Code/go/src/github.com/cosmtrek/air/runner/engine.go:178 +0x36a

OS: Windows x64 and Ubuntu 16.04 LTS (Windows subsystem)

Please support absolute paths other than the root directory

configs:

root = "/data/project"
# Optional! If `watch_dir` is empty, use `root`.
watch_dir = ""
tmp_dir = "tmp"

[build]
# Just plain old shell command. You could use `make` as well.
cmd = "go build -o ./cmd/server/server ./cmd/server"
# Binary file yields from `cmd`.
bin = "./cmd/server/server"
# Customize binary.
full_bin = "./cmd/server/server -c ./configs/config.toml -m ./configs/model.conf"

errors:

can't load package: package ./cmd/server: cannot find package "." in:
        /root/cmd/server

Binary not stopping on Ctrl + C on windows

OS: Windows 7 x64
Terminal: mintty 2.8.4 (MINGW64 git-scm)

Config:

# Config file for [Air](https://github.com/cosmtrek/air) in TOML format

# Working directory
# . or absolute path, please note that the directories following must be under root
root = "."
# Optional! If `watch_dir` is empty, use `root`.
watch_dir = ""
tmp_dir = "tmp"

[build]
# Just plain old shell command. You could use `make` as well.
cmd = "govvv build"
# Binary file yields from `cmd`.
bin = "./api.exe"
# This log file places in your tmp_dir.
log = "air_errors.log"
# Watch these filename extensions.
include_ext = ["go", "tpl", "tmpl", "html", "env"]
# Ignore these filename extensions or directories.
exclude_dir = ["migrations", "assets", "tmp", "vendor"]
# There's no necessary to trigger build each time file changes if it's too frequency.
delay = 1500 # ms
# Stop to run old binary when build errors occur.
stop_on_error = true

[log]
# Show log time
time = false

[color]
# Customize each part's color. If no color found, use the raw app log.
main = "magenta"
watcher = "cyan"
build = "yellow"
runner = "green"
# app = "white"

Steps to reproduce:

  1. Create go project with http.ListenAndServe and a blank handler.
  2. Start Air air in Terminal
  3. Access the handler endpoint exmaple: http://localhost.com:1234/my_endpoint/
  4. Ctrl + C in Terminal.

Air is closed but binary is still running when checked in Task Manager.

how to run air with environment variables

  • this line blew is not work
    cmd = "MONGODB_HOST=127.0.0.1:27017 MONGODB_USER=test MONGODB_PASSWORD=test REDIS_ADDR=127.0.0.1 GIN_MODE=debug go run *.go"

  • this line blew works well
    MONGODB_HOST=127.0.0.1:27017 MONGODB_USER=test MONGODB_PASSWORD=test REDIS_ADDR=127.0.0.1 GIN_MODE=debug air

.air.conf

# Config file for [Air](https://github.com/cosmtrek/air) in TOML format

# Working directory
# . or absolute path, please note that the directories following must be under root.
root = "." 
tmp_dir = "tmp"

[runner]
# Just plain old shell command. You could use `make` as well.
cmd = "MONGODB_HOST=127.0.0.1:27017 MONGODB_USER=test MONGODB_PASSWORD=test REDIS_ADDR=127.0.0.1 GIN_MODE=debug go run *.go"
# Binary file yields from `cmd`.
bin = "tmp/main"
# Customize binary.
# full_bin = "APP_ENV=dev APP_USER=air ./tmp/main"
# Watch these filename extensions.
include_ext = ["go", "tpl", "tmpl", "html"]
# Ignore these filename extensions or directories.
exclude_dir = ["assets", "vendor", "frontend/node_modules"]
# Watch these directories if you specified.
include_dir = []
# Exclude files.
exclude_file = []
# It's not necessary to trigger build each time file changes if it's too frequent.
delay = 1000 # ms
# Stop to run old binary when build errors occur.
stop_on_error = true
# This log file places in your tmp_dir.
log = "air_errors.log"

[log]
# Show log time
time = false

[color]
# Customize each part's color. If no color found, use the raw app log.
main = "magenta"
watcher = "cyan"
build = "yellow"
runner = "green"

[misc]
# Delete tmp directory on exit
clean_on_exit = true

never reached

I can not specify the config file.

➜  git:(master) ✗ air -c .air.conf


  __    _   ___  
 / /\  | | | |_) 
/_/--\ |_| |_| \_ v1.12.1 // live reload for Go apps, with Go1.14.0

2020/04/26 13:38:46 (16, 64): never reached
➜  git:(master) ✗ 
# Config file for [Air](https://github.com/cosmtrek/air) in TOML format

# Working directory
# . or absolute path, please note that the directories following must be under root.
root = "."
tmp_dir = "tmp"

[build]
# Just plain old shell command. You could use `make` as well.
cmd = "go build -o ./tmp/main ."
# Binary file yields from `cmd`.
bin = "GIN_MODE=debug tmp/main"
# Customize binary.
full_bin = "GIN_MODE=debug ./tmp/main"
# Watch these filename extensions.
include_ext = ["go", "tpl", "tmpl", "html","toml","env","json",,"xml","js","css"]
# Ignore these filename extensions or directories.
exclude_dir = ["assets", "tmp", "vendor", "frontend/node_modules"]
# Watch these directories if you specified.
include_dir = []
# Exclude files.
exclude_file = []
# This log file places in your tmp_dir.
log = "air.log"
# It's not necessary to trigger build each time file changes if it's too frequent.
delay = 1000 # ms
# Stop running old binary when build errors occur.
stop_on_error = true
# Send Interrupt signal before killing process (windows does not support this feature)
send_interrupt = false
# Delay after sending Interrupt signal
kill_delay = 500 # ms

[log]
# Show log time
time = true

[color]
# Customize each part's color. If no color found, use the raw app log.
main = "magenta"
watcher = "cyan"
build = "yellow"
runner = "green"

[misc]
# Delete tmp directory on exit
clean_on_exit = true

[feature expect] support symbolic link

air is an awesome toy.
Actually I'm fresh player over 3 years until I meet air.

Here’s an advice.
I have a few symbolic links in my sources directory.

May 14 15:27:47 2020 go.mod
May 14 15:27:47 2020 go.sum
May 15 07:41:40 2020 main.go
Apr 30 11:00:30 2020 pb -> ../other-project/pb
Apr 25 09:59:06 2020 route

Hope air can imporve to support them like this

exclude_dir = ["pb"]
exclude_ext = ["pb/*.pb.go"]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.